Skip to content

Instantly share code, notes, and snippets.

@mlafeldt
Created February 24, 2011 09:09
Show Gist options
  • Save mlafeldt/841944 to your computer and use it in GitHub Desktop.
Save mlafeldt/841944 to your computer and use it in GitHub Desktop.
[Python] paramiko examples
#!/usr/bin/env python
import sys, paramiko
if len(sys.argv) < 5:
print "args missing"
sys.exit(1)
hostname = sys.argv[1]
password = sys.argv[2]
source = sys.argv[3]
dest = sys.argv[4]
username = "root"
port = 22
try:
t = paramiko.Transport((hostname, port))
t.connect(username=username, password=password)
sftp = paramiko.SFTPClient.from_transport(t)
sftp.get(source, dest)
finally:
t.close()
#!/usr/bin/env python
import sys, paramiko
if len(sys.argv) < 4:
print "args missing"
sys.exit(1)
hostname = sys.argv[1]
password = sys.argv[2]
command = sys.argv[3]
username = "admin"
port = 22
try:
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy)
client.connect(hostname, port=port, username=username, password=password)
stdin, stdout, stderr = client.exec_command(command)
print stdout.read(),
finally:
client.close()
@kritisingh
Copy link

Hi Ricardo,
I want to pass encrypted password to connect method. How can I do that. I could not find the documentation on paramiko site.

@HollywoodMarks
Copy link

Hi kritisingh,
You could use getpass for that: https://pymotw.com/2/getpass/

@roastercode
Copy link

That is fine with ssh ... but in "pure paramiko" how would you formulate http://docs.paramiko.org/en/2.4/api/sftp.html#paramiko.sftp_client.SFTPClient.listdir ?

@Premalatha2007
Copy link

How can I ssh to multiple devices

Copy link

ghost commented May 27, 2019

Hey can anyone tell me that, is SSH exploit public key script is available or not,

@raviteja-oops
Copy link

how to write command for windows remote server path.

@ojpojao
Copy link

ojpojao commented Dec 7, 2020

Hey,

how can I use these openssh options on paramiko?

ssh -oHostKeyAlgorithms=+ssh-dss -oKexAlgorithms=+diffie-hellman-group1-sha1  -c aes256-cbc user@host

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment