如何解决“ paramiko.ssh_exception.SSHException:无法从ssh-agent获取密钥”

时间:2019-03-23 17:08:46

标签: python python-3.x ssh centos paramiko

我正在尝试使用Paramiko Python模块通过SSH连接到远程服务器。使用Python版本3.6.7在CentOS 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;

1 个答案:

答案 0 :(得分:0)

如果您不想使用身份验证代理,则可以避免Paramiko尝试使用SSHClient.connectallow_agent参数与之联系:

ssh.connect("19.16.2.2", username="user1", password="pass", allow_agent=False)