Skip to content

Instantly share code, notes, and snippets.

@tthtlc
Created September 29, 2018 06:52
Show Gist options
  • Save tthtlc/52b459dad851caf55aa593b842f4916b to your computer and use it in GitHub Desktop.
Save tthtlc/52b459dad851caf55aa593b842f4916b to your computer and use it in GitHub Desktop.
import paramiko
ssh = paramiko.SSHClient()
key = paramiko.RSAKey.from_private_key_file("id_rsa.pem")
###openssl rsa -in /path/to/encrypted/key -out /paht/to/decrypted/key
### remember to decrypt as it is encrypted by default (output as id_rsa.pem)
#key = paramiko.DSSKey.from_private_key_file(keyfilename)
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("172.17.0.2", username="root", pkey=key)
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command("ls -axptr")
output=ssh_stdout.readlines()
print '\n'.join(output)
ssh.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment