4

I've created an Amazon EC2 AMI running CentOS Linux 5.5 and PostgreSQL 8.4. I'd like to be able to create an SSH tunnel from my machine to the instance so I can connect to the PostgreSQL database from my development machine (JDBC, Tomcat, etc.) I haven't modified the PostgreSQL configuration at all as of yet. I can successfully SSH into the instance from a command line, and have run the following command to try and create my tunnel:

ssh -N -L2345:<My instance DNS>:5432 -i <keypair> root@<My instance DNS>

I don't receive any errors when initially running this command. However, when I try and use psql to open up a connection on localhost:2345, the connection fails.

Any thoughts as to why this is happening?

Shadowman
  • 11,150
  • 19
  • 100
  • 198

1 Answers1

5

The first <My instance DNS> should be localhost. And you probably don't want to/need to ssh as root.

Peter Eisentraut
  • 35,221
  • 12
  • 85
  • 90
  • can't be localhost in both places, otherwise I'm not specifying the Amazon EC2 instance to connect to. – Shadowman Jan 04 '11 at 21:35
  • The *first* one should be localhost. The second is how you connect to the EC2 instance from your workstation. – Peter Eisentraut Jan 05 '11 at 04:33
  • Still not working. I get the following error message from psql: psql: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. I also see this message in the window where I'm running the SSH command: channel 2: open failed: connect failed: Connection refused – Shadowman Jan 08 '11 at 23:18
  • It's working now. The service had crashed. Once I restarted it everything started working as expected. Thanks! – Shadowman Jan 08 '11 at 23:58
  • The command in the question seems a bit malformed.. here's what works for me: `ssh -L 2345:localhost:5432 -i ~/.ssh/mykey.pem ubuntu@ec2-instance` – Stephen Fuhry Jun 17 '12 at 21:36