Hacking with Python Series: Python libraries for SSH

SSH stands for secure shell, one of the vastly used and exploited protocol. If not configured correctly, anyone can have entire access of your system with it. Many Worms have exploited the network using SSH.It works on the port 22. In this Hacking with python series, I will give you an introduction of different libraries that can help you make connection with SSH in python. The libraries which are mentioned below will only work on Linux OS. NOT ON WINDOWS.

There are mainly two libraries that I had came across:

  1. Paramiko 
  2. Pexpect’s Pxssh

From the above two I find Pxssh much more reliable, doesn’t mean Paramiko is not that reliable!

Paramiko Library

Install it in your linux OS using command:

pip install paramiko

Sometimes, the older version gets installed for paramiko. The older version of paramiko have known host bug in it, generating an error while connection to client. So you must use an upgraded version. To upgrade the paramiko using terminal use command:

pip install –upgrade paramiko

Paramiko library will provide a client-server based structure for SSH connection. Paramiko also provides other cryptography handling features but we will stick to SSH for now. The documentation for Paramiko provides all the example you need to understand its working. It provides handling of keys too! It also provides handlers to send command and get output for stdin and stdout. It also provide file upload and download features from the server.

Paramiko Usage Docs

 

Pexpect’s Pxssh Library

Install Pxssh using command:

pip install pexpect

In the package pexpect we will be looking at the library pxssh. It is the library that helps us make connection with SSH and also send and retrieve commands from the server. It mainly provide you control of commands.Provide feature such as login, logout and prompt.

Pxssh Library Docs

 

In the next article, you will find the code for both Paramiko and pxssh and how they work!

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: