我正在尝试使用Paramiko Python模块通过SSH连接到远程服务器。在CentOS 7服务器上使用Python 3.6.7版安装。但是得到以下错误。
python
import paramiko
>>> ssh = paramiko.SSHClient()
>>> ssh.load_system_host_keys()
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh.connect("19.16.2.2", username="user1", password="pass")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/paramiko/client.py", line 424, in connect
passphrase,
File "/usr/local/lib/python3.6/site-packages/paramiko/client.py", line 643, in _auth
self._agent = Agent()
File "/usr/local/lib/python3.6/site-packages/paramiko/agent.py", line 372, in __init__
self._connect(conn)
File "/usr/local/lib/python3.6/site-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
请注意,我不想仅使用Paramiko模块来使用SSH代理。
我用Google搜索并尝试了以下解决方案。我仍然无法解决这个问题。如果提供解决方案,将不胜感激提前致谢。
# eval ssh-agent -s
SSH_AUTH_SOCK=/tmp/ssh-PycvG5kzoTjt/agent.26174; export SSH_AUTH_SOCK;
SSH_AGENT_PID=26175; export SSH_AGENT_PID;
如果您不想使用身份验证代理,可以使用allow_agent
的SSHClient.connect
参数来避免Paramiko尝试联系它:
ssh.connect("19.16.2.2", username="user1", password="pass", allow_agent=False)