Skip to content

Instantly share code, notes, and snippets.

@batok
Created April 10, 2012 16:11
Show Gist options
  • Star 94 You must be signed in to star a gist
  • Fork 26 You must be signed in to fork a gist
  • Save batok/2352501 to your computer and use it in GitHub Desktop.
Save batok/2352501 to your computer and use it in GitHub Desktop.
Paramiko example using private key
import paramiko
k = paramiko.RSAKey.from_private_key_file("/Users/whatever/Downloads/mykey.pem")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print "connecting"
c.connect( hostname = "www.acme.com", username = "ubuntu", pkey = k )
print "connected"
commands = [ "/home/ubuntu/firstscript.sh", "/home/ubuntu/secondscript.sh" ]
for command in commands:
print "Executing {}".format( command )
stdin , stdout, stderr = c.exec_command(command)
print stdout.read()
print( "Errors")
print stderr.read()
c.close()
@vickyvikas7988
Copy link

Converting the key
resolves the error
ssh-keygen -p -m PEM -f ~/.ssh/id_rsa

@dovanpho
Copy link

dovanpho commented May 7, 2021

thanks.
if your private key is in .ppk, you need convert to .pem.

@rdiazg14
Copy link

I resolve this problem with version paramiko-2.10.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment