Python: How can remote from my local pc to remoteA to remoteb to remote c using Paramiko

戏子无情 提交于 2019-11-27 04:57:20

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/15818328/python-how-can-remote-from-my-local-pc-to-remotea-to-remoteb-to-remote-c-using

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!