我試圖使用Paramiko從Python連接到SSH服務器。這是我到目前爲止的嘗試:Paramiko - 在OS X上使用加密的私鑰文件
>>> import paramiko
>>> import os
>>> privatekeyfile = os.path.expanduser('~/.ssh/id_rsa')
>>> mykey = paramiko.RSAKey.from_private_key_file(privatekeyfile)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/paramiko/pkey.py", line 198, in from_private_key_file
key = cls(filename=filename, password=password)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/paramiko/rsakey.py", line 51, in __init__
self._from_private_key_file(filename, password)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/paramiko/rsakey.py", line 163, in _from_private_key_file
data = self._read_private_key_file('RSA', filename, password)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/paramiko/pkey.py", line 280, in _read_private_key_file
data = self._read_private_key(tag, f, password)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/paramiko/pkey.py", line 323, in _read_private_key
raise PasswordRequiredException('Private key file is encrypted')
paramiko.PasswordRequiredException: Private key file is encrypted
正如你所看到的,它失敗了,因爲我的私鑰被加密。但是,密碼存儲在我的OS X登錄鑰匙串中,當我輸入ssh host
時,它不會詢問它(相反,它只會詢問一次,然後記住它直到下次重新啓動)。有沒有一種方法可以使paramiko
使用密碼/從鑰匙鏈中取回它,就像ssh
那樣?
我剛剛創建了一個沒有密碼並使用它的新密鑰對,但接受了這個,因爲這可能會起作用 – houbysoft 2013-04-24 22:34:59
這是我自己的解決方案,當遇到這種情況@houbysoft ...它只是沒有回答這個問題:-)。 – Ben 2013-04-26 17:04:44
那麼,密碼正在用作密碼解密?因爲我剛剛嘗試過,它不起作用! – 2016-04-07 23:19:58