I would like to know how to to jump from one remote server to another remote server using paramiko. I want to ssh from my local pc to remote-A then from remote-A to remote-B and from remote- B to remote-C.
import paramiko
def connect(ip, usr, psw):
client = paramiko.SSHClient()
client.load_host_keys('/home/dgomez/.ssh/known_hosts')
client.connect(ip, username=usr, password=psw)
return client
host1 = connect('192.168.1.2', 'username', 'password')
# Here I'm connect to remote-A
Now I would to know how can I connect from Remote-A to Remote-B.
use for pexpect module it is very useful for you http://www.noah.org/wiki/pexpect and and pexpect module simplified in pxssh module that very good for remote login http://dsnra.jpl.nasa.gov/software/Python/site-packages/Contrib/pxssh.html simple code:
import pxssh
host = pxssh.pxssh
host.login('hostname','username','password')
host.sendline('command')#'ls'
print host.before
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.