0
我通過sudo ssh-keygen -t rsa -b 4096
創建了一個RSA密鑰對並將其複製到.ssh
文件夾中。我正在使用Python的paramiko包。我的代碼是:Python-Parmiko錯誤:'RSAKey'對象不可迭代'
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
幫助表示讚賞,因爲這讓我絕望。
非常感謝你! –
@MrMeeseeks如果這解決了您的問題,您應該將此答案標記爲解決方案。 – Jakuje