Skip to content

Instantly share code, notes, and snippets.

@mr-karan
Created November 26, 2016 12:55
Show Gist options
  • Save mr-karan/273f2b6e1af6f29b7208a95568751a73 to your computer and use it in GitHub Desktop.
Save mr-karan/273f2b6e1af6f29b7208a95568751a73 to your computer and use it in GitHub Desktop.
import paramiko
ip='server ip'
port=22
username='username'
password='password'
cmd='some useful command'
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip,port,username,password)
stdin,stdout,stderr=ssh.exec_command(cmd)
outlines=stdout.readlines()
resp=''.join(outlines)
print(resp)
stdin,stdout,stderr=ssh.exec_command('some really useful command')
outlines=stdout.readlines()
resp=''.join(outlines)
print(resp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment