与 postgresql 的连接挂在 OSX 上的 SSH 隧道上

use*_*333 3 postgresql ssh mac-osx ssh-tunnel

尝试连接到 OSX 上的远程 PG 服务器,但它一直超时。

首先,我设置了隧道:

ssh -L 5433:serverip:5432 user@serverip
Run Code Online (Sandbox Code Playgroud)

然后在一个单独的终端中,我尝试连接到 PG:

psql -h localhost -p 5433 -U user
Run Code Online (Sandbox Code Playgroud)

此处的连接仅持续约 3 分钟。然后我收到以下消息:

psql: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
Run Code Online (Sandbox Code Playgroud)

在 ssh 隧道终端上,我看到的是:

channel 3: new [direct-tcpip]
(3 mins later:)channel 3: open failed: connect failed: Connection timed out
Run Code Online (Sandbox Code Playgroud)

我已经尝试了我能想到的所有变体(localhost vs 127.0.0.1,不同的用户名)。没有任何工作。这个确切的设置在 Windows Putty 上运行良好,所以它不是服务器。我也可以在服务器上 ssh 和运行 psql,所以它不是 PG。

Jak*_*uje 8

我相信您已postgresql配置为仅在 loopbavk ( localhost)上收听。您应该像这样使用转发:

ssh -L 5433:localhost:5432 user@serverip
Run Code Online (Sandbox Code Playgroud)

否则它会尝试连接到您服务器的公共 IP,那里没有任何监听或没有授权登录。