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

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

首先,我build立了隧道:

ssh -L 5433:serverip:5432 user@serverip 

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

 psql -h localhost -p 5433 -U user 

这里的连接只需要3分钟。 然后我得到以下消息:

 psql: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. 

在ssh隧道terminal上,我看到的只是这个:

 channel 3: new [direct-tcpip] (3 mins later:)channel 3: open failed: connect failed: Connection timed out 

我试过了我能想到的所有变化(localhost vs 127.0.0.1,diff用户名)。 没有任何工作。 这个确切的设置在Windows Putty上工作正常,所以它不是服务器。 我也能SSH和运行在服务器上的psql,所以它不是PG。

我相信你有postgresqlconfiguration只监听loopbavk( localhost )。 你应该使用这样的转发:

 ssh -L 5433:localhost:5432 user@serverip 

否则,它会尝试连接到您的服务器的公共IP,在哪里没有听或没有授权login。