Search This Blog

Saturday, August 11, 2012

How to execute remote commands from python over ssh connection

There are a number of possible solution for Python that allow you to execute a command remotely. Below is a list of libraries/modules I found when researching it.
  1. paramiko
  2. http://www.lag.net/paramiko/
    http://pypi.python.org/pypi/paramiko/1.7.7.2

  3. ssh module ( a wrapper for paramiko)
  4. http://stackoverflow.com/questions/1939107/python-libraries-for-ssh-handling
    http://media.commandline.org.uk/code/ssh.txt

  5. pythion binding to C libssh library
  6. http://www.no-ack.org/2010/11/python-bindings-for-libssh2.html

  7. fabric
  8. http://docs.fabfile.org/en/1.4.3/index.html>

  9. python SSH module (base on the paramiko)
  10. http://pypi.python.org/pypi/ssh/1.7.11 
    https://github.com/bitprophet/ssh
An interesting introduction to the paramiko can be found here: SSH Programming with Paramiko

This is a simple python example as well.

3 comments:

  1. you should also do a
    ssh.close()
    at the end to close the connection.

    ReplyDelete
  2. Thanks for your comment! I've added it to the example code.

    ReplyDelete
  3. Thanks so much. It works well

    ReplyDelete