致命:尝试通过 SSH 隧道连接到 PostgreSQL 服务器的主机"::1"没有 pg_hba.conf 条目



我正在尝试通过SSH隧道连接到java的postgresql服务器。 我没有对 postgresql 服务器的管理员访问权限,所以我无法修改任何设置。

这是我的代码:

public SSHConnection() {
JSch jsch = new JSch();
//First ssh connection to the first domain (SERVER1_DOMAIN)
serverSession = jsch.getSession(USERNAME, SERVER1_DOMAIN, 22);
serverSession.setPassword(PASSWORD);
localUserInfo lui=new localUserInfo();
serverSession.setUserInfo(lui);
serverSession.setConfig(STRICT_HOST_KEY_CHECKING, NO);
System.out.println("Establishing Connection with "+SERVER1_DOMAIN);
//Port forwarding to the second domain (SERVER2_DOMAIN)
serverSession.setPortForwardingL(2233, SERVER2_DOMAIN, 22);
serverSession.connect();
System.out.println("Connection established with "+SERVER1_DOMAIN);
serverSession.openChannel("direct-tcpip");
//Creating second ssh session
dbstudSession = jsch.getSession(USERNAME, "localhost", 2233);
dbstudSession.setPassword(PASSWORD);
dbstudSession.setUserInfo(lui);
dbstudSession.setConfig("StrictHostKeyChecking", "no");
dbstudSession.connect(); // now we're connected to the secondary system
//Creating port forwarding from my system (6786) to postgresql port of SERVER2_DOMAIN over the ssh connection created above
dbstudSession.setPortForwardingL(6786,"localhost",5432);
System.out.println("Connection established with "+SERVER2_DOMAIN);
Class.forName("org.postgresql.Driver");
Connection connection = null;
//Trying to connect to the psql database
connection = DriverManager.getConnection("jdbc:postgresql://localhost:6786/databasename",USERNAME,PASSWORD);
connection.close();
}

当我运行它时,它正确地创建了两个 ssh 连接,但我从 postgre 收到此错误:

致命:主机"::1"、用户"taschinfed"、数据库 "taschinfed"、SSL 关闭没有 pg_hba.conf 条目 at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:473( at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:205( at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49( at org.postgresql.jdbc.PgConnection.(页连接.java:195( at org.postgresql.Driver.makeConnection(Driver.java:452( at org.postgresql.Driver.connect(Driver.java:254( at java.sql.DriverManager.getConnection(DriverManager.java:664( at java.sql.DriverManager.getConnection(DriverManager.java:247( at SSHConnection.connect(SSHConnection.java:65( 在SSHConnection。(SSHConnection.java:54( at Main.main(Main.java:10(

我不知道该怎么办

编辑:我可以通过 windows power shell 轻松访问数据库,方法是创建一个到第一个域的 ssh 连接,然后使用psql命令从第一个域到第二个域的另一个 ssh 连接。这意味着 ssh 连接没有问题,实际上我可以通过我的 java 代码访问服务器,但我不明白该错误消息是什么意思。

发现问题: 在行中

dbstudSession.setPortForwardingL(6786,"localhost",5432);

我用该服务器的实际地址(SERVER2_DOMAIN(更改了"localhost",一切正常。我仍然不明白问题可能是什么。

最新更新