Centos7的 paramiko 认证失败
来源:4-12 paramiko模块ssh用户密钥登录
慕移动0419469
2018-01-26
无论我用 DSA 还是 RSA 都会得到认证失败的异常
dsa 的时候我也有生生成 id_dsa
In [1]: import paramiko
In [2]: ssh = paramiko.SSHClient()
In [3]: ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
In [4]: key_file = paramiko.DSSKey.from_private_key_file('/root/.ssh/id_dsa')
In [5]: ssh.connect('192.168.1.117',22,'root',pkey=key_file)
---------------------------------------------------------------------------
AuthenticationException Traceback (most recent call last)
<ipython-input-5-b181b849fa0a> in <module>()
----> 1 ssh.connect('192.168.1.117',22,'root',pkey=key_file)
~/virtualenv/skops/lib/python3.6/site-packages/paramiko/client.py in connect(self, hostname, port, username, password, pkey, key_filename, timeout, allow_agent, look_for_keys, compress, sock, gss_auth, gss_kex, gss_deleg_creds, gss_host, banner_timeout, auth_timeout, gss_trust_dns, passphrase)
422 username, password, pkey, key_filenames, allow_agent,
423 look_for_keys, gss_auth, gss_kex, gss_deleg_creds, t.gss_host,
--> 424 passphrase,
425 )
426
~/virtualenv/skops/lib/python3.6/site-packages/paramiko/client.py in _auth(self, username, password, pkey, key_filenames, allow_agent, look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host, passphrase)
712 # if we got an auth-failed exception earlier, re-raise it
713 if saved_exception is not None:
--> 714 raise saved_exception
715 raise SSHException('No authentication methods available')
716
~/virtualenv/skops/lib/python3.6/site-packages/paramiko/client.py in _auth(self, username, password, pkey, key_filenames, allow_agent, look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host, passphrase)
689 # in ['password']
690 allowed_types = set(
--> 691 self._transport.auth_publickey(username, key))
692 two_factor = (allowed_types & two_factor_types)
693 if not two_factor:
~/virtualenv/skops/lib/python3.6/site-packages/paramiko/transport.py in auth_publickey(self, username, key, event)
1448 # caller wants to wait for event themselves
1449 return []
-> 1450 return self.auth_handler.wait_for_response(my_event)
1451
1452 def auth_interactive(self, username, handler, submethods=''):
~/virtualenv/skops/lib/python3.6/site-packages/paramiko/auth_handler.py in wait_for_response(self, event)
224 if issubclass(e.__class__, PartialAuthentication):
225 return e.allowed_types
--> 226 raise e
227 return []
228
AuthenticationException: Authentication failed.
1回答
-
Jeson
2018-01-26
先这么确认下:
1、将id_dsa的key文件拷贝到一台linux的服务器上,用ssh -i key路径 的方式连接测试,看看是否还是有认证失败的问题。
2、查看下服务端的公钥文件的权限
# ll ~/.ssh -d
drwx------ 2 root root 4096 1月 6 21:57 /root/.ssh/ (权限需要为700)
# ll ~/.ssh/
-rw-------. 1 root root 406 1月 6 08:56 authorized_keys (权限需要为600)
00
相似问题