简体   繁体   English

Python SSH paramiko问题 - 来自ssh会话内部的ssh

[英]Python SSH paramiko issue - ssh from inside of ssh session

import paramiko

client = paramiko.SSHClient()
client.load_system_host_keys()
ip = '192.168.100.6'
client.connect(ip, username='root', password='mima')
i, o, e = client.exec_command('apt-get install sl -y --force-yes')
print o.read(), e.read()
client.close()

i used this example.. it is working fine but i want after login server1 to login server2 i mean nested ssh . 我用这个例子..它工作正常,但我想登录server1后登录server2我的意思是嵌套ssh。

can't you call the ssh command from inside of your client.exec_command? 你不能从client.exec_command里面调用ssh命令吗?
like: 喜欢:

client.exec_command('ssh user@host2 "apt-get install sl -y --force-yes"')

You exec the command "ssh" in the client, and not apt-get. 你在客户端执行命令“ssh”,而不是apt-get。

You can't really start a paramiko session on the client as long as your python program isn't there. 只要你的python程序不存在,你就无法真正在客户端上启动paramiko会话。 The software you start using ssh must live on that machine. 您开始使用ssh的软件必须在该计算机上运行。

Perhaps first scp a copy of your software, and start that using a parameter like -recursive_lvl = 1 ? 也许首先scp你的软件副本,并使用像-recursive_lvl = 1这样的参数启动它?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM