openssh-wrapper

OpenSSH Python wrapper
Download

openssh-wrapper Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Publisher Name:
  • NetAngels team
  • Publisher web site:
  • https://github.com/NetAngels/

openssh-wrapper Tags


openssh-wrapper Description

OpenSSH Python wrapper Under some circumstances simple wrapper around OpenSSH ssh command-line utility seems more preferable than paramiko machinery.openssh-wrapper proposes yet another hopefully thin wrapper around ssh to execute commands on remote servers. All you need thereis to make sure that OpenSSH client and Python interpreter are installed, and then install openssh-wrapper package.Usage sampleSimple command execution>>> from openssh_wrapper import SSHConnection>>> conn = SSHConnection('localhost', 'root')>>> ret = conn.run('whoami')>>> print retcommand: whoamistdout: rootstderr:returncode: 0>>> ret.command'whoami'>>> ret.stdout'root'>>> ret.stderr''>>> ret.returncode0If python interpreter is installed on a remote machine, you can also run pieces of python code remotely. The same is true for any other interpreter which can execute code from stdin>>> ret = conn.run('whoami')>>> print conn.run('print "Hello world"', interpreter='/usr/bin/python').stdoutHello worldYet another userful run method option is forward_ssh_agent (the feature which paramiko doesn't yet have). Suppose you have access as support to foobar server while root@localhost does not, so you can take advantage of SSH agent forwarding$ eval `ssh-agent`Agent pid 5272$ ssh-addIdentity added: /home/me/.ssh/id_rsa (/home/,e/.ssh/id_rsa)$ python>>> conn = SSHConnection('localhost', 'root')>>> print conn.run('ssh support@foobar "whoami"', forward_ssh_agent=True).stdoutsupportAnd finally there is a sample which shows how to copy a file from local to remote machine>>> fd = open('test.txt', 'w')>>> fd.write('Hello world')>>> fd.close()>>> from openssh_wrapper import SSHConnection>>> conn = SSHConnection('localhost', 'root')>>> conn.scp('test.txt', target='/tmp')>>> print conn.run('cat /tmp/test.txt').stdoutHello world Requirements: · Python


openssh-wrapper Related Software