Created
November 4, 2014 14:55
-
-
Save mrbitsdcf/0c857460dd19898e98f7 to your computer and use it in GitHub Desktop.
SSH with embeeded private key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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