歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Python學習筆記-SSH連接

Python學習筆記-SSH連接

日期:2017/3/1 9:43:03   编辑:Linux編程

主要是通過paramiko庫實現SSH連接功能

import os
import paramiko

host = '192.168.10.10'
port = 22
username = 'Hadoop'
password = 'hadoop'

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
private_key_file = os.path.expanduser('C:/Program Files/VMware/VMware Share/id_rsa')
mykey = paramiko.RSAKey.from_private_key_file(private_key_file)
ssh.connect(host, port, username, password, pkey = mykey, timeout = 300)
stdin, stdout, stderr = ssh.exec_command('ls .')
print stdout.read()
ssh.close()

《Python核心編程 第二版》.(Wesley J. Chun ).[高清PDF中文版] http://www.linuxidc.com/Linux/2013-06/85425.htm

《Python開發技術詳解》.( 周偉,宗傑).[高清PDF掃描版+隨書視頻+代碼] http://www.linuxidc.com/Linux/2013-11/92693.htm

Python腳本獲取Linux系統信息 http://www.linuxidc.com/Linux/2013-08/88531.htm

在Ubuntu下用Python搭建桌面算法交易研究環境 http://www.linuxidc.com/Linux/2013-11/92534.htm

Python 的詳細介紹:請點這裡
Python 的下載地址:請點這裡

Copyright © Linux教程網 All Rights Reserved