python與ssh互動

來源:互聯網
上載者:User

標籤:iss   運行   service   shel   without   互動   src   .com   ddp   

由於pexpect模組在windows上不能運行,官方給出的。

所以我使用了paramiko模組進行我們的互動。

我的linux是Debian Kali Linux 64位

首先我們要進vim的/etc/ssh/sshd_config把#PermitRootLogin  without-password 的#去掉,without-password改為yes

#PasswordAuthentication no 該行前面的#去掉,並且將NO修改為YES;

原因:linux安全機制預設不允許使用root登入ssh,改完以後重啟kali,並開啟ssh服務。

service ssh start

代碼環節:

自行安裝parmiko

pip install parmiko

 

import parmikossh=parmiko.SSHClient()#建立一個對象ssh.set_missing_host_key_policy(parmiko.AutoAddPolicy())try:  ssh.connect("192.168.223.128",22,"root","root")#串連目標,IP,連接埠,username,passwordexcept Exception:  print("Not Password Found")stdin,stdout,stderr=ssh.exec_command("ifconfig")#這是成功串連上後想在目標shell執行的命令for std in stdout.readlines():  print(std)ssh.close()

運行py的

代碼圖:

轉載請注釋來自:本地址

 

python與ssh互動

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.