How to SSH tunnel and connect to a database using IntelliJ and JDBC?

前端 未结 3 1700
攒了一身酷
攒了一身酷 2021-02-20 14:15

I\'m having issues connecting to a database hosted on a server using IntelliJ and JDBC. With the command line, the command:

ssh username@server -L 11100:ct1:2801         


        
相关标签:
3条回答
  • 2021-02-20 15:00

    If the error is Exhausted available authentication methods (1), make sure that the passphrase (2) is provided if required. This is easy to forget because the passphrase is often supplied automatically by the OS keyring manager, which makes it seem like the key does not have one.

    The credentials in (3) are for Postgres. These will not work with peer authentication. In my case, I needed this in pg_hba.conf:

    hostnossl  all  rdahl  127.0.0.1/32  md5
    

    The proxy host and user in (4) are for the ssh server as seen from the client.

    The docs from JetBrains are odd and left me in doubt if this is just using an existing SSH tunnel, or if it creates one. It creates one.

    The Test Connection buttons in the two dialogs both trigger the same test.

    0 讨论(0)
  • 2021-02-20 15:08

    Do you connect to SSH server from a java client like SSHJ (https://github.com/hierynomus/sshj) ?

    The URL on your DriverManager seems wrong: try port 11100 instead.

    0 讨论(0)
  • 2021-02-20 15:11

    Here's my setup via intellij if anyone is looking for simple solution without external libraries.

    1. Open Database view (View -> Tool Windows -> Database).
    2. Add new DataSource (right-click, New -> Data Source -> Postgres/Mysql). In host, use 127.0.0.1 (not localhost, sometimes localhost is not properly resolved).
    3. Fill in rest of the fields as configured on your remote host.

    Now click on SSH/SSL tab and configure ssl tunnel:

    0 讨论(0)
提交回复
热议问题