python paramiko example

Started by ggnfs000, January 12, 2017, 06:07:23 PM

Previous topic - Next topic

ggnfs000

python paramiko example

Here I post the simple working paramiko example. The web has full of junk on the usage of paramiko, conflicting information, incomplete, inaccurate documentation. Had to sift through a lot of garbage to get this working. I am not a fun of python programming language (it is not actually a real programming language, rather poorly documented scripting language that runs slow by default) at all just has to use it.

This is done RHEL6.5 with Python 2.7.

yum install python-paramiko.noarch -y


#!/usr/bin/python
import paramiko

try:
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.WarningPolicy())

    client.connect("10.0.0.26", port="22", username="root", password=<password>)

    stdin, stdout, stderr = client.exec_command("ls -l /")
    print stdout.read(),

finally:
    client.close()

print "done."





Source: python paramiko example