Skip to content

Instantly share code, notes, and snippets.

@maldevel
Last active October 16, 2016 09:13
Show Gist options
  • Save maldevel/870e87774e203c8fbeb440e54b7aeeb4 to your computer and use it in GitHub Desktop.
Save maldevel/870e87774e203c8fbeb440e54b7aeeb4 to your computer and use it in GitHub Desktop.
Perform commands over ssh with Python
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('example.com', username='username', password='password')
stdin, stdout, stderr = ssh.exec_command('ls')
lines = stdout.readlines()
for line in lines:
if line.strip():
print line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment