Python 使用Paramiko通过另一台服务器连接到服务器
我试图使用Paramiko进入服务器,然后进入服务器中的路由器,然后运行命令 但是,我没有得到路由器的密码输入,然后它只是关闭连接Python 使用Paramiko通过另一台服务器连接到服务器,python,ssh,paramiko,Python,Ssh,Paramiko,我试图使用Paramiko进入服务器,然后进入服务器中的路由器,然后运行命令 但是,我没有得到路由器的密码输入,然后它只是关闭连接 username, password, port = ... router = ... hostname = ... client = paramiko.SSHClient() client.load_system_host_keys() client.set_missing_host_key_policy(paramiko.WarningPolicy) clien
username, password, port = ...
router = ...
hostname = ...
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy)
client.connect(hostname, port = port, username = username, password = password)
cmd = # ssh hostname@router
# password input comes out here but gets disconnected
stdin, stdout, stderr = client.exec_command(cmd)
HERE # command to run in the router
stdout.read()
client.close()
有什么帮助吗?首先,您最好使用端口转发(又称SSH隧道)通过另一台服务器连接到服务器 看
无论如何,要回答您的字面问题:
ssh
在提示输入密码时需要终端,因此您需要设置的get_pty
参数(这可能会给您带来很多讨厌的副作用)
ssh
)输入
ssh
输入。看
stdin, stdout, stderr = client.exec_command(cmd, get_pty=True)
stdin.write('password\n')
stdin.flush()
stdin.write('subcommand\n')
stdin.flush()