Python-刺激:原始错误:身份验证失败。并且无法使用私钥连接到计算机

时间:2019-01-21 23:07:44

标签: python ssh ssh-keys private-key

最近,我一直在尝试创建一个使用项目的私钥登录到计算机的功能。到目前为止,我还无法使用按键登录。我试图连接到我自己的计算机上进行测试。我在paramiko中尝试了相同的代码,并得到了类似的错误。就是我的电脑吗?

我正在使用python模块spur,并收到错误消息(最后一行错误):

Original error: Authentication failed.

这是我的代码:

import spur
shell = spur.SshShell(
    hostname="192.168.1.1",
    username="User1",
    private_key_file="/Users/User1/.ssh/id_dsa",
    missing_host_key=spur.ssh.MissingHostKey.accept
)
with shell:
    result = shell.run(["echo", "hello"])

我希望在屏幕上得到输出“ hello”(回声),但是却出现了错误(整个错误):

Traceback (most recent call last):
  File "/Users/User1/ssh_tests/ssh_key_test.py", line 9, in <module>
result = shell.run(["echo", "hello"])
  File "/Library/Python/2.7/site-packages/spur/ssh.py", line 166, in run
return self.spawn(*args, **kwargs).wait_for_result()
  File "/Library/Python/2.7/site-packages/spur/ssh.py", line 178, in spawn
channel = self._get_ssh_transport().open_session()
  File "/Library/Python/2.7/site-packages/spur/ssh.py", line 268, in _get_ssh_transport
raise self._connection_error(error)
spur.ssh.ConnectionError: Error creating SSH connection
Original error: Authentication failed.

0 个答案:

没有答案