linux - 如何使用中间计算机隧道到另一台计算机? SSH

标签 linux networking ssh port tunnel

我在本地计算机上,我只想测试反向 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

如果满足以下条件,此方法有效:

  1. 第二台计算机可以访问第三台计算机
  2. 第二台计算机上的 sshd 配置允许 TCP 转发(默认为"is")

关于linux - 如何使用中间计算机隧道到另一台计算机? SSH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16826597/

相关文章:

linux - 无法使用 IMU 制造商的 python2.7 示例脚本传递 OSC 数据

python - 有没有办法以编程方式获取 ps 输出?

c - __asm__ ("movl %eax,%esp") 返回什么?

networking - 如何将已知的自签名服务器标记为受 wget 信任

python - 通过 Internet 传输数据的最简单方法,Python

linux - ip_append_data 中的一个问题

ssh - Ansible 无法与 SSH 连接(横幅交换)

linux - 编写我自己的内核

git - Jenkins 的 npm install 无法安装托管在 bitbucket 上的模块

git - OS X上的Git-CodeCommit URL问题