xxxx@toad:~$ rm .ssh/kNown_hosts
另一个选择是您在Windows中登录意味着检查命令提示符。如果您尝试在Windows中登录,则意味着要使用pexpect
child = pexpect.spawn('ssh tiger@172.16.0.190 -p 8888')
child.logfile = open("/tmp/mylog", "w")
print child.before
child.expect('.*Are you sure you want to continue connecting (yes/no)?')
child.sendline("yes")
child.expect(".*assword:")
child.sendline("tiger\r")
child.expect('Press any key to continue...')
child.send('\r')
child.expect('C:\Users\.*>')
child.sendline('dir')
child.prompt('C:\Users\.*>')
为了使其更加健壮,它将shell提示设置为比$或#更独特的内容。这应该适用于大多数Borne / Bash或Csh样式的shell。 http://www.pythonforbeginners.com/code-snippets-source-code/ssh-connection- with-python/