0

I want to ssh to a server where authentication is done via a public key

ssh ssh_username@server_ipaddress -p port number

and after this, want to access a postgresql database

psql -h host_name -U user_name database_name

How to connect using any IDE

I have tried using

sudo ssh -L 6666:127.0.0.1:3306 <your_SSH_username>@<remoteserver.com>

What another approach can I use?

3

2 Answers 2

1

You can try to ssh to remote server this way:

ssh -L 6666:host_name:5432 ssh_username@server_ipaddress -p portnumber

and then connect to database server from your local machine:

psql -h 127.0.0.1 -p 6666 -U user_name database_name

or using Java with same connection parameters.

Sign up to request clarification or add additional context in comments.

2 Comments

can you explain me purpose of both these steps... thanks
@gshivam63 First step is a local port forwarding. It forwards any connection to local port 6666 to port 5432 on host_name through ssh. You need this step because you don't have direct access to database server host from your local machine. Second step is just for testing your connection.
0
ssh ssh_hostname@ssh_ipaddress -p ssh_portnumber 

psql -h db_hostname -U db_username db_name 
password:xyz 

Solution:

Terminal

$ ssh -L 6666:db_hostname:5432 ssh_hostname@ssh_ipaddress -p ssh_portnumber

after that when ssh to server, enter command

$ psql -h db_hostname -U db_username db_name

To connect from within NetBeans use:

Netbeans->Services->Postgresql=> Connect 

using

  • DriverName: PostgreSQL
  • Host: localhost
  • Database: db_name
  • port: 6666
  • username: db_username
  • password: xyz

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.