系统环境
centos7.2 python3.7 paramiko 2.11.0
报错如下,但是直接通过ssh是可以通过验证并连上服务器
Traceback (most recent call last):
File "remote_ssh.py", line 19, in <module>
ssh.connect(host,22,'root',pkey=key,timeout=10)
File "/usr/local/python37/lib/python3.7/site-packages/paramiko/client.py", line 446, in connect
passphrase,
File "/usr/local/python37/lib/python3.7/site-packages/paramiko/client.py", line 766, in _auth
raise saved_exception
File "/usr/local/python37/lib/python3.7/site-packages/paramiko/client.py", line 742, in _auth
self._transport.auth_publickey(username, key)
File "/usr/local/python37/lib/python3.7/site-packages/paramiko/transport.py", line 1635, in auth_publickey
return self.auth_handler.wait_for_response(my_event)
File "/usr/local/python37/lib/python3.7/site-packages/paramiko/auth_handler.py", line 259, in wait_for_response
raise e
paramiko.ssh_exception.AuthenticationException: Authentication failed.
解决方案
- 方法一: 添加 disabled_algorithms=dict(pubkeys=["rsa-sha2-512", "rsa-sha2-256"])
ssh.connect(host,22,'root',pkey=key,timeout=10,disabled_algorithms=dict(pubkeys=["rsa-sha2-512", "rsa-sha2-256"]))
- 方法二:最后发现这台机器openssh-server版本过低
yum update openssh-server -y