Skip to content

Instantly share code, notes, and snippets.

@ghawkgu
Created April 27, 2011 10:18
Show Gist options
  • Select an option

  • Save ghawkgu/944017 to your computer and use it in GitHub Desktop.

Select an option

Save ghawkgu/944017 to your computer and use it in GitHub Desktop.

Revisions

  1. ghawkgu revised this gist Apr 27, 2011. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions ssh_client_with_key.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #!/usr/bin/env python

    import paramiko

    hostname = '192.168.1.1'
    port = 22
    username = 'foo'
    pkey_file = '/home/foo/.ssh/id_rsa'

    if __name__ == "__main__":
    key = paramiko.RSAKey.from_private_key_file(pkey_file)
    s = paramiko.SSHClient()
    s.load_system_host_keys()
    s.connect(hostname, port, pkey=key)
    stdin, stdout, stderr = s.exec_command('ifconfig')
    print stdout.read()
    s.close()
  2. ghawkgu created this gist Apr 27, 2011.
    17 changes: 17 additions & 0 deletions ssh_client.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #!/usr/bin/env python

    import paramiko

    hostname = 'localhost'
    port = 22
    username = 'foo'
    password = 'xxxYYYxxx'

    if __name__ == "__main__":
    paramiko.util.log_to_file('paramiko.log')
    s = paramiko.SSHClient()
    s.load_system_host_keys()
    s.connect(hostname, port, username, password)
    stdin, stdout, stderr = s.exec_command('ifconfig')
    print stdout.read()
    s.close()