Python-Parmiko错误:' RSAKey'对象不可迭代'

时间:2016-11-09 08:05:00

标签: python ssh rsa paramiko openssh

我通过sudo ssh-keygen -t rsa -b 4096创建了一个RSA密钥对,并将其复制到.ssh文件夹。我正在使用Python paramiko包。我的代码是:

import paramiko
k = paramiko.RSAKey.from_private_key_file('/home/username/.ssh/id_rsa', password='mypassphrase')
s = paramiko.SSHClient()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
conn = s.connect('remote_computer', username ='username', port=22, key_filename =k)
command = 'sudo python ~/pythonscript.py'
(stdin, stdout, stderr) = s.exec_command(command)
s.close()

但是当我尝试运行代码时,我收到以下错误和回溯:

Traceback (most recent call last):
File "pythonparamikoscript.py", line 6, in <module>
conn = s.connect('remote_computer', username ='username', port=22, key_filename =k)
File "/usr/lib/python2.7/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.7/dist-packages/paramiko/client.py", line 441, in _auth
for key_filename in key_filenames:
TypeError: 'RSAKey' object is not iterable

非常感谢帮助,因为这让我感到绝望。

1 个答案:

答案 0 :(得分:0)

connect()接受不同的论点:

  • key_filename (str)这是您应该分配密钥的地方
  • conn = s.connect('remote_computer', username ='username', port=22, pkey=k) 这只是一个包含密钥位置的字符串。

正在运行

this.router.navigate([
    '/search',
    'chicago',
    {
        place: 'restaurant'
    }
]);

应该做的。