2015-06-22 66 views
1

我有PostgreSQL服務器和一臺單獨的計算機是它的客戶端。他們在一個網絡中。如果我使用psql的命令一樣通過SSH隧道在PostgreSQL上進行身份驗證失敗

psql --host db_ip_address --port 5432 --user user base_name

連接出現罰款,所有的作品。

但是,如果我將打開SSH隧道來像DB服務器:

ssh -L 63333:localhost:5432 [email protected]_ip_address

,然後嘗試做相同的,如:

psql --host localhost --port 63333 --user user base_name

比它突然輸出錯誤信息:

psql: FATAL: Ident authentication failed for user "user"

pg_hba.conf的服務器上有這樣的臺詞:

# TYPE DATABASE  USER   ADDRESS     METHOD 

# "local" is for Unix domain socket connections only 
local all    all          trust 
# IPv4 local connections: 
host all    all    127.0.0.1/32   trust 
host all    all    192.168.0.49/32   trust 
host all    all    192.168.0.50/32   trust 
host all    all    192.168.0.48/32   trust 
# IPv6 local connections: 
host all    all    ::1/128     ident 

我需要,因爲我確實需要一個更隧道自己的電腦使用SSH隧道,它要得到有關它的數據庫連接的唯一途徑。 而且我不想更改任何配置或基於PostgreSQL服務器,因爲它在實時服務器上工作。 希望有所幫助。

回答

2

根據錯誤消息和pg_hba.conf,服務器將localhost解析爲其IPv6地址,該地址綁定到ident身份驗證。

作爲一個解決方案,您可以:

  • 變化pg_hba.conf設置trust方法::1/128,因爲已經是127.0.0.1/32

  • 的情況下或運行psql --host 127.0.0.1 --port 63333 [other options]...迫使IPv4地址。

+0

實際上,這看起來像一個解決方案。我只是使用 '''ssh -L 63333:127.0.0.1:5432 root @ db_ip_address'''來建立隧道,並且突然生效!感謝名單! – Pycz