决定第一次尝试 Python,如果答案很明显,请见谅。
我正在尝试使用 paramiko 创建一个 ssh 连接。我正在使用以下代码:
#!/home/bin/python2.7
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("somehost.com", username="myName", pkey="/home/myName/.ssh/id_rsa.pub")
stdin, stdout, stderr = ssh.exec_command("ls -l")
print stdout.readlines()
ssh.close()
很标准的东西,对吧?除了我收到此错误:
./test.py
Traceback (most recent call last):
File "./test.py", line 10, in <module>
ssh.connect("somehost", username="myName", pkey="/home/myName/.ssh/id_rsa.pub")
File "/home/lib/python2.7/site-packages/paramiko/client.py", line 327, in connect
self._auth(username, password, pkey, key_filenames, allow_agent, look_for_keys)
File "/home/lib/python2.7/site-packages/paramiko/client.py", line 418, in _auth
self._log(DEBUG, 'Trying SSH key %s' % hexlify(pkey.get_fingerprint()))
AttributeError: 'str' object has no attribute 'get_fingerprint'
它指的是什么“str”对象?我以为我只需要将路径传递给 RSA 密钥,但它似乎需要一些对象。