Python学习笔记-SSH连接

2014-11-23 22:22:21 · 作者: · 浏览: 9

主要是通过paramiko库实现SSH连接功能


import os
import paramiko


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()