pysftp — paramiko SSHException, Bad host key from server

我的未来我决定 提交于 2019-12-04 12:36:56

Workaround

This seems to be some sort of bug with the pysftp wrapper... I'm not sure. Reverting to native paramiko got me connected just fine, so I'm going with that for now. Current working code:

rsa_key = paramiko.RSAKey.from_private_key_file('~/.ssh/the_key', password='myPassword')
transport = paramiko.Transport((inventory[0],8055))
transport.connect(username='theUser', pkey=rsa_key)
sftp = paramiko.SFTPClient.from_transport(transport)
print sftp.listdir()

For me, once I had the host public key loaded in .ssh\known_hosts, the cookbook example worked.

But, I don't recall being prompted to ever save the host public key to my .ssh\known_hosts file.

This link is what helped me understand the host public key was separate from my own public/private key pair. I'm using exavault and they provide the public/private key pair, but did not provide the host public key.

I used ssh-keyscan using git bash for windows:

$ ssh-keyscan example.com
# example.com SSH-2.0-OpenSSH_5.3
example.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQAB...

and copied the key to my known_hosts file. Then it worked with pysftp 0.2.9.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!