Running remote command using SSH in python

How to run command remotely using SSH in python ?

#!/usr/bin/python                                                               
import paramiko

HOST = "www.codingpointer.com"

ssh_client = paramiko.SSHClient()
#Add missing client key
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
#connection
ssh_client.connect(HOST,username='heat-admin')
print "SSH connection is established to %s" %HOST
#runs command and reads the output using stdout
stdin, stdout, stderr = ssh_client.exec_command('date')
print stdout.read()                                                                                
                                                             

Output:
$ python dp-ssh.py 
SSH connection is established to www.codingpointer.com
Fri Feb 16 14:16:22 UTC 2018

Privacy Policy  |  Copyright@2017 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^