Friday, March 11, 2016

Paramiko SSH Client in Python

Paramiko is a SSH client in Python This can be used to invoke commands without logging into the ssh terminal. It can be used in scripting when you have to deal with remote machines in a programmatic way.

For Paramiko, first install the module

pip install paramiko

A simple program for paramiko is as follows:


import paramiko

# initialize the client
client = paramiko.SSHClient()


# Auto add the remote host. 

# Can also specify password in place of key file
client.connect(<address of remote host>,  
               username=<user in remote machine>
               key_filename= <ssh private key file>)

# Now you can fire a remote command e.g. making a directory
stdin, stdout, stderr = client.exec_command('mkdir temp')

# Print the exit status. 0 tells that the command was success
print("Exit status: " + str(

# At the end close the client

No comments:

Post a Comment