aws 服务器:paramiko 问题
aws server : paramiko issue
虽然我通常可以使用 ssh 命令连接到服务器:
>[ec2-user@dsi_valid_env:~/scripts]$ssh test@172.XX.YY.ZZ
>test@172.XX.YY.ZZ's password:
但我正在努力连接 paramiko 以获得 python 脚本:
>>> import paramiko
>>> ssh = paramiko.SSHClient()
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh.connect("172.XX.YY.ZZ",username="test",password="test")
paramiko.ssh_exception.SSHException: could not get keys from ssh-agent
你知道我做错了什么吗?
在我的 ssh.connect 的调试堆栈跟踪下方:
ssh.connect("172.XX.YY.ZZ",username="test",password="test")
DEBUG:paramiko.transport:starting thread (client mode): 0x24532d0L
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_5.3)
DEBUG:paramiko.transport:kex algos:[u'diffie-hellman-group-exchange-sha256', u'diffie-hellman-group-exchange-sha1', u'diffie-hellman-group14-sha1', u'diffie-hellman-group1-sha1'] server key:[u'ssh-rsa', u'ssh-dss'] client encrypt:[u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'arcfour256', u'arcfour128', u'aes128-cbc', u'3des-cbc', u'blowfish-cbc', u'cast128-cbc', u'aes192-cbc', u'aes256-cbc', u'arcfour', u'rijndael-cbc@lysator.liu.se'] server encrypt:[u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'arcfour256', u'arcfour128', u'aes128-cbc', u'3des-cbc', u'blowfish-cbc', u'cast128-cbc', u'aes192-cbc', u'aes256-cbc', u'arcfour', u'rijndael-cbc@lysator.liu.se'] client mac:[u'hmac-md5', u'hmac-sha1', u'umac-64@openssh.com', u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-ripemd160', u'hmac-ripemd160@openssh.com', u'hmac-sha1-96', u'hmac-md5-96'] server mac:[u'hmac-md5', u'hmac-sha1', u'umac-64@openssh.com', u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-ripemd160', u'hmac-ripemd160@openssh.com', u'hmac-sha1-96', u'hmac-md5-96'] client compress:[u'none', u'zlib@openssh.com'] server compress:[u'none', u'zlib@openssh.com'] client lang:[u''] server lang:[u''] kex follows?False
DEBUG:paramiko.transport:Ciphers agreed: local=aes128-ctr, remote=aes128-ctr
DEBUG:paramiko.transport:using kex diffie-hellman-group14-sha1; server key type ssh-rsa; cipher: local aes128-ctr, remote aes128-ctr; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none
DEBUG:paramiko.transport:Switch to new keys ...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/dist-packages/paramiko/client.py", line 307, in connect
look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
File "/usr/lib/python2.6/dist-packages/paramiko/client.py", line 456, in _auth
self._agent = Agent()
File "/usr/lib/python2.6/dist-packages/paramiko/agent.py", line 339, in __init__
self._connect(conn)
File "/usr/lib/python2.6/dist-packages/paramiko/agent.py", line 68, in _connect
raise SSHException('could not get keys from ssh-agent')
paramiko.ssh_exception.SSHException: could not get keys from ssh-agent
ssh.connect(username="172.XX.YY.ZZ",username="test",password="test")
更改为:
ssh.connect("172.XX.YY.ZZ",username="test",password="test")
我发现了问题,
我改变了:
ssh.connect("172.XX.YY.ZZ",username="test",password="test")
至:
ssh.connect("172.XX.YY.ZZ",username="test",password="test", allow_agent=False)
显然在某些情况下切换到 "password authentification" 并不是完全自动的
虽然我通常可以使用 ssh 命令连接到服务器:
>[ec2-user@dsi_valid_env:~/scripts]$ssh test@172.XX.YY.ZZ
>test@172.XX.YY.ZZ's password:
但我正在努力连接 paramiko 以获得 python 脚本:
>>> import paramiko
>>> ssh = paramiko.SSHClient()
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh.connect("172.XX.YY.ZZ",username="test",password="test")
paramiko.ssh_exception.SSHException: could not get keys from ssh-agent
你知道我做错了什么吗?
在我的 ssh.connect 的调试堆栈跟踪下方:
ssh.connect("172.XX.YY.ZZ",username="test",password="test")
DEBUG:paramiko.transport:starting thread (client mode): 0x24532d0L
INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_5.3)
DEBUG:paramiko.transport:kex algos:[u'diffie-hellman-group-exchange-sha256', u'diffie-hellman-group-exchange-sha1', u'diffie-hellman-group14-sha1', u'diffie-hellman-group1-sha1'] server key:[u'ssh-rsa', u'ssh-dss'] client encrypt:[u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'arcfour256', u'arcfour128', u'aes128-cbc', u'3des-cbc', u'blowfish-cbc', u'cast128-cbc', u'aes192-cbc', u'aes256-cbc', u'arcfour', u'rijndael-cbc@lysator.liu.se'] server encrypt:[u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'arcfour256', u'arcfour128', u'aes128-cbc', u'3des-cbc', u'blowfish-cbc', u'cast128-cbc', u'aes192-cbc', u'aes256-cbc', u'arcfour', u'rijndael-cbc@lysator.liu.se'] client mac:[u'hmac-md5', u'hmac-sha1', u'umac-64@openssh.com', u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-ripemd160', u'hmac-ripemd160@openssh.com', u'hmac-sha1-96', u'hmac-md5-96'] server mac:[u'hmac-md5', u'hmac-sha1', u'umac-64@openssh.com', u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-ripemd160', u'hmac-ripemd160@openssh.com', u'hmac-sha1-96', u'hmac-md5-96'] client compress:[u'none', u'zlib@openssh.com'] server compress:[u'none', u'zlib@openssh.com'] client lang:[u''] server lang:[u''] kex follows?False
DEBUG:paramiko.transport:Ciphers agreed: local=aes128-ctr, remote=aes128-ctr
DEBUG:paramiko.transport:using kex diffie-hellman-group14-sha1; server key type ssh-rsa; cipher: local aes128-ctr, remote aes128-ctr; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none
DEBUG:paramiko.transport:Switch to new keys ...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/dist-packages/paramiko/client.py", line 307, in connect
look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
File "/usr/lib/python2.6/dist-packages/paramiko/client.py", line 456, in _auth
self._agent = Agent()
File "/usr/lib/python2.6/dist-packages/paramiko/agent.py", line 339, in __init__
self._connect(conn)
File "/usr/lib/python2.6/dist-packages/paramiko/agent.py", line 68, in _connect
raise SSHException('could not get keys from ssh-agent')
paramiko.ssh_exception.SSHException: could not get keys from ssh-agent
ssh.connect(username="172.XX.YY.ZZ",username="test",password="test")
更改为:
ssh.connect("172.XX.YY.ZZ",username="test",password="test")
我发现了问题,
我改变了:
ssh.connect("172.XX.YY.ZZ",username="test",password="test")
至:
ssh.connect("172.XX.YY.ZZ",username="test",password="test", allow_agent=False)
显然在某些情况下切换到 "password authentification" 并不是完全自动的