我见过几个与这个主题相关的问题和答案,但我一直无法掌握如何操作。
这有可能吗,有人知道办法吗?
提前谢谢你。
发布于 2016-05-20 08:25:09
您必须打开隧道,检查paramiko演示或使用sshtunnel
包。对于后者:
import paramiko as pk
import sshtunnel
with sshtunnel.open_tunnel(
remote_computer_ip,
ssh_username=remote_username,
ssh_password=remote_password,
remote_bind_address=(NAS_IP, 22),
debug_level='DEBUG',
) as tunnel:
ssh = pk.SSHClient()
ssh.set_missing_host_key_policy(pk.AutoAddPolicy())
ssh.connect(NAS_IP,
port=tunnel.local_bind_port, # redirected to port NAS_IP:22
username=NAS_USER,
password=NAS_PASS)
(stdin, stdout, stderr) = ssh.exec_command(...) # your stuff
发布于 2016-05-19 14:02:39
你可以用更简单的方式来问这个问题。如果我没有错,你是否试图用paramiko连接到一台机器,从那台机器上连接到NAS机器?
或者您是否连接到1台机器,比如说A,然后您想要该机器的ssh句柄,并连接到NAS机器并生成另一个ssh句柄?
如果是后者,我建议您使用一个类并为每个ssh连接创建一个对象。你可以看看这个:
https://stackoverflow.com/questions/37324836
复制相似问题