Saturday
Aug132011
Paramiko: easy, native ssh in Python...
posted on:
2011-Aug-13 13:25
2011-Aug-13 13:25 I just discovered Paramiko (docs here)! This module allows SSH interaction natively (meaning directly through code, and not through system calls), and supports a pretty comprehensive scope of operations over ssh. The key items that caught my attention are:
- Intutive syntax and application
-
mysshclient = paramiko.SSHClient() mysshclient.connect('hostadd',username='user',password='pass')
- Addressed the missing host key issue we are all familiar with directly on the shell
mysshclient = paramiko.SSHClient() mysshclient.set_missing_host_key_policy(paramiko.AutoAddPolicy())
-
- Key based authentication
- Terrific example here
-
mysshclient = paramiko.SSHClient() mysshclient.set_missing_host_key_policy(paramiko.AutoAddPolicy()) privateKeyPath = '/path/to/your/key' privateKey = paramiko.RSAKey.from_private_key_file(privateKeyPath) mysshclient.connect('hostaddr',username='user',pkey=privateKey)
- Send commands and interact with output on the remote machine
-
mysshclient = paramiko.SSHClient() mysshclient.set_missing_host_key_policy(paramiko.AutoAddPolicy()) mysshclient.connect('hostaddr',username='user',password='pass') stderr, stdout, stdin = myssh.exec_command('ls -latrh') stdout.readlines()
-
Brilliant. Will be applying Paramiko to a teeny automation script that will start an Amazon EC2 instance, run a series of commands on the server (neat scraping and analysis stuff I hope to write more about), and then process some post shutdown ops.


Reader Comments