paramiko quickstart

当您用paramiko进行ssh编程如遇到如下一个错误提示,请参考下面两个代码,关键的代码行后面做了注释

import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # Very import
ssh.connect('10.60.2.92', username='root', password='keep_secret')
stdin, stdout, stderr = ssh.exec_command('df -h')
for line in stdout.readlines(): print line,

ssh.close()

-- or ---

import paramiko
import os
ssh = paramiko.SSHClient()

known_host = os.path.expanduser("~/.ssh/known_hosts")
ssh.load_system_host_keys(known_host) # Very import
ssh.connect('10.60.2.92', username='root', password='keep_secret')
stdin, stdout, stderr = ssh.exec_command('df -h')
for line in stdout.readlines(): print line,

ssh.close()

你可能感兴趣的:(编程,ssh,OS)