How to ssh connect through python Paramiko with ppk public key How to ssh connect through python Paramiko with ppk public key python python

How to ssh connect through python Paramiko with ppk public key


Ok @Adam and @Kimvais were right, paramiko cannot parse .ppk files.

So the way to go (thanks to @JimB too) is to convert .ppk file to openssh private key format; this can be achieved using Puttygen as described here.

Then it's very simple getting connected with it:

import paramikossh = 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()


For me I doing this:

import paramikohostname = 'my hostname or IP' myuser   = 'the user to ssh connect'mySSHK   = '/path/to/sshkey.pub'sshcon   = paramiko.SSHClient()  # will create the objectsshcon.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # no known_hosts errorsshcon.connect(hostname, username=myuser, key_filename=mySSHK) # no passwd needed

works for me pretty ok


To create a valid DSA format private key supported by Paramiko in Puttygen.

Click on Conversions then Export OpenSSH Key

enter image description here