通过跳转主机使用Python Paramiko进行连接,该主机提供目标服务器的交互式选择

问题描述 投票:0回答:1
我正在尝试通过跳转服务器使用 SSH 协议连接到服务器。当我使用协议通过终端进行连接时,跳转服务器会打开一个 shell,并从提供的可用服务器列表中请求服务器编号,然后输入用户名或密码。使用 Paramiko 库。

我的代码:

import paramiko client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect( hostname="server_ip", username="user", password="pass", look_for_keys=False, allow_agent=False ) com='1' stdin, stdout, stderr = client.exec_command(com) data = stdout.read() + stderr.read() print(data.decode('utf-8'))
我收到消息:

目标无效。

我在跳转服务器上的 shell 看起来像这样:


enter image description here

python ssh paramiko
1个回答
0
投票
您的跳转服务器可能仅在交互式 shell 会话中显示选择。因此,您必须使用

SSHClient.invoke_shell

,否则在自动化连接时这样做并不是一件好事。

另请参阅

Paramiko 上的 exec_command 和使用 invoke_shell() 发送有什么区别?

© www.soinside.com 2019 - 2024. All rights reserved.