I have a network bastion which is publicly accessible at
example.compute-1.amazonaws.com and a private postgres database instance at
I can ssh into the bastion using
$ ssh -i key.pem firstname.lastname@example.org
Then once I'm in the bastion I create a ssh tunnel with:
$ ssh -i key.pem -L 5432:postgres.example.us-east-1.rds.amazonaws.com:5432 email@example.com
I can then verify that the tunnel works by connecting to the database from the bastion using localhost:
$ psql -p 5432 -h localhost -U postgres
However, I am unable to connect to the database remotely (without being in the bastion).
$ psql -p 5432 -h example.compute-1.amazonaws.com -U postgres psql: could not connect to server: Connection refused Is the server running on host "example.compute-1.amazonaws.com" () and accepting TCP/IP connections on port 5432?
I've configured the security group of the bastion to accept inbound traffic on port 5432.
Am I using
ssh -L correctly? Should I be using it outside the bastion? Any advice would be much appreciated.