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()
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
开关。
SSHClient.invoke_shell
,就像 demos/demo.py
那样。