Skip to content

Instantly share code, notes, and snippets.

@mrbitsdcf
Created November 4, 2014 14:55
Show Gist options
  • Save mrbitsdcf/0c857460dd19898e98f7 to your computer and use it in GitHub Desktop.
Save mrbitsdcf/0c857460dd19898e98f7 to your computer and use it in GitHub Desktop.
SSH with embeeded private key
import paramiko
import StringIO
rsakey_string = 'Put your RSA Private Key string here'
''' alternative method:
rsakey_string = open('/path/to/rsa_private_key_file').read()
'''
keyfile = StringIO.StringIO(rsakey_string)
mykey = paramiko.RSAKey.from_private_key(keyfile)
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('myserver', username='ubuntu', pkey=mykey)
stdin, stdout, stderr = ssh.exec_command('uptime')
stdout.readlines()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment