What is the best way to connect to a remote database server that can only be accessed from a different ec2 instance?

StackOverflow https://stackoverflow.com/questions/18109912

  •  23-06-2022
  •  | 
  •  

Pergunta

How would I go about connecting to a database that can only be accessed through an ssh tunnel to an ec2 instance. The current route would be:

My ubuntu laptop -> ec2 instance -> postgres database server

  • I have complete control over the ec2 instance.
  • I only have access to port 5432 of the remote database server via the ec2 instance. It lives on a different server.

I have been accessing the database using the terminal but would prefer to be lazy and use something like pgAdmin or RazorSQL. I am assuming I can do an ssh tunnel to my ec2 instance, then some sort of port forward to the database server but I haven’t been able to get beyond the ssh tunnel.

A double hop ssh tunnel will not work because I don’t have ssh access to the DB server.

Thanks!

Foi útil?

Solução

You want to do something like this - where ec2-dbserver is your database server (inside EC2), and ec2-host is the host that you can ssh2.

You should then be able to point pgadmin-III to localhost:5432

ssh -L 5432:ec2-dbserver:5432 user@ec2-host 
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top