相当于Paramiko中的远程端口转发命令 `ssh -R 80:localhost:8080 [email protected]` 是什么?

问题描述 投票:0回答:1

ssh -R 80:localhost:8080 [email protected]
相当于Paramiko中的什么? 我搜索了很多但没有成功...... 我试过的代码

import paramiko

command = "df"

# Update the next three lines with your
# server's information

username = "localhost:9876"
host = "[email protected]"

client = paramiko.client.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host,port=80, username=username)
_stdin, _stdout,_stderr = client.exec_command("df")
print(stdout.read().decode())
client.close()
python ssh paramiko portforwarding
1个回答
0
投票

部分等效是

Transport.request_port_forward

但这只会设置转发的服务器端部分。建立从 SSH 客户端 (Paramiko) 到本地服务器的本地连接的本地实现取决于您。

demos/rforward.py
中给出了如何实现它的示例。

您的命令的等效项将是:

python3 rforward.py -u nokey -p 80 -r 127.0.0.1:8080 localhost.run

请注意,

rforward.py
脚本不会启动 shell。它只是进行转发。所以它实际上相当于
ssh
-N
开关

如果您同时需要转发和 shell,则需要修改脚本以另外执行

SSHClient.invoke_shell
,就像
demos/demo.py
那样。

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