问题描述
我想知道如何使用 paramiko 从一个远程服务器跳转到另一个远程服务器.我想从我的本地 PC SSH 到远程 A,然后从远程 A 到远程 B,再从远程 B 到远程 C.
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
现在我想知道如何从 Remote-A 连接到 Remote-B.
Now I would to know how can I connect from Remote-A to Remote-B.
推荐答案
使用 pexpect 模块对你很有用 http://www.noah.org/wiki/pexpect和 pexpect 模块在 pxssh 模块中简化,非常适合远程登录 http://dsnra.jpl.nasa.gov/software/Python/site-packages/Contrib/pxssh.html简单代码:
use for pexpect module it is very useful for you http://www.noah.org/wiki/pexpectand and pexpect module simplified in pxssh module that very good for remote login http://dsnra.jpl.nasa.gov/software/Python/site-packages/Contrib/pxssh.htmlsimple code:
import pxssh
host = pxssh.pxssh
host.login('hostname','username','password')
host.sendline('command')#'ls'
print host.before
这篇关于Python:如何使用Paramiko从我的本地PC远程到remoteA到remoteb到远程c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!