我在本地计算机上,我只想测试反向 ssh,以便我访问计算机 2 并通过计算机 2 访问计算机 3,并使计算机 3 响应我,假设我想访问计算机 3 上的 postgresql。
如何使用 ssh 和使用端口来做到这一点? 5432是sql的端口
我的方法是这样的:
ssh -L 3000:localhost:5432 <ipaddressof the 2nd computer>
所以我现在在第二台计算机中。
在终端中再次输入:
ssh -L 3000:localhost:5432 <ipaddress of the 3rd computer>
我现在在第三台电脑里。我不知道该怎么办了,如何访问它的sql?
我尝试了这段代码,但不起作用:
psql -U myusername -p 3000
最佳答案
尝试以下操作:
ssh -L localhost:3000:<ip address 3rd computer>:5432 <ip address 2nd computer>
然后:
psql -U myusername -h localhost -p 3000
如果满足以下条件,此方法有效:
- 第二台计算机可以访问第三台计算机
- 第二台计算机上的 sshd 配置允许 TCP 转发(默认为"is")
关于linux - 如何使用中间计算机隧道到另一台计算机? SSH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16826597/