在我的例子中,涉及四个服务器,它们是:
D: the target HTTPS server, which can only be directly accessed by C, but not A or B;
C: a Ubuntu box, which can only be directly accessed by B, but not A;
B: a CentOS box, which can be directly accessed by A
A: the working environment, Ubuntu我的目标是让我的Python代码在A上运行,从D下载HTTPS-数据。我在A/B/C上拥有root或sudo权限,所以我将在A<-> B <->C之间设置SSH隧道,并利用C<->D之间的直接可访问性,以便A可以从D下载数据。
首先,作为检查B<->C<->D的连接性的一种尝试,我可以让运行在B上的代码通过以下步骤从D下载数据:
ssh -N -D 9988 C_user@C_host_ip -p C_sshd_port并输入B_user密码import requests
headers={'User-agent': 'Mozilla'}
proxies={'https': 'socks5h://127.0.0.1:9988'}
r = requests.get(D_url, headers=headers, proxies=proxies)代码运行正常。
Secondly,为了使整个链A<->B<-> C <->D,我尝试在A上做一个从B到C的ssh隧道,但是失败了:
ssh -N -L 9988:C_host_ip:C_sshd_port B_user@B_host_ip并输入B_user的密码socks.GeneralProxyError: SOCKS5 proxy server sent invalid data的错误我对SSH隧道的理解可能是错误的。我该怎么做才能完成这个目标?谢谢。
发布于 2022-04-23 10:47:34
在网上找到了这并成功地进行了测试。
为了简短起见,我应该在第二次中对B使用这个命令
ssh -N -L 9988:localhost:9988 B_user@B_host_ip其中,第一个9988是本地主机上的侦听端口(如python代码中的socks5h主机设置),第二个9988是我在B主机上使用的端口(如在B主机上发出的命令)。
信用是对上面链接的原始海报。
https://stackoverflow.com/questions/71977422
复制相似问题