我正在使用 Paramiko通过 SSH 连接到服务器。
基本身份验证运行良好,但我无法理解如何使用公钥连接。
当我连接 PuTTY 时,服务器会告诉我:
Using username "root".
Authenticating with public key "rsa-key@ddddd.com"
Passphrase for key "rsa-key@ddddd.com": [i've inserted the passphrase here]
Last login: Mon Dec 5 09:25:18 2011 from ...
我用这个 ppk 文件连接到它:
PuTTY-User-Key-File-2: ssh-rsa
Encryption: aes256-cbc
Comment: rsa-key@dddd.com
Public-Lines: 4
[4 lines key]
Private-Lines: 8
[8 lines key]
Private-MAC: [hash]
使用基本身份验证,我得到的错误(来自日志)是:
DEB [20111205-09:48:44.328] thr=1 paramiko.transport: userauth is OK
DEB [20111205-09:48:44.927] thr=1 paramiko.transport: Authentication type (password) not permitted.
DEB [20111205-09:48:44.927] thr=1 paramiko.transport: Allowed methods: ['publickey', 'gssapi-with-mic']
我尝试包含该 ppk 文件并设置为 auth_public_key
,但没有成功。
你能帮帮我吗?
最佳答案
好的,@Adam 和@Kimvais 是对的,Paramiko 无法解析 .ppk 文件。
所以要走的路(也感谢@JimB)是将 .ppk 文件转换为 OpenSSH 私钥格式;这可以使用 PuTTYgen 来实现如所述here .
那么连接起来就很简单了:
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('<hostname>', username='<username>', password='<password>', key_filename='<path/to/openssh-private-key-file>')
stdin, stdout, stderr = ssh.exec_command('ls')
print stdout.readlines()
ssh.close()
关于python - 如何使用 ppk 公钥通过 Python Paramiko 进行 ssh 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8382847/