Navigation
Powered by Squarespace
Sidebar
« DARPA Shredder Challenge - Preliminary (quarter-baked) thoughts... | Main | Mint.com let me down today... »
Saturday
Aug132011

Paramiko: easy, native ssh in Python...

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.

 

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>