Search code examples
amazon-web-servicesterminalamazon-rdsssh-tunnel

Can't open a ssh tunnel from my linux shell (EC2 exposing an RDS db)


I'm struggling trying to open an ssh tunnel to access an RDS MySql instance through an EC2 bastion host. Using desktop clients (Navicat, MysqlWorkBench) with ssh tunnel set everything works as expected but when I run ssh -i keys.pem user@ec2-instance -L 3307:rds-mysql-instance:3306 -N in my terminal the command hangs indefinitely.

I can access my EC2 instance using ssh -i keys.pem user@ec2-instance and from my EC2 instance I can access the RDS database

Am I missing something in the configuration? I also tried to open all ports on my Security Group just to be sure that it wasn't a port related issue.

Any help/idea?


Solution

  • Based on the comments.

    To identify the issue, more verbose output from ssh can be requested using -v, -vv or even -vvv flags. Thus, the command for debugging can be:

    ssh -i keys.pem user@ec2-instance -L 3307:rds-mysql-instance:3306 -N -vv
    

    The detailed output allowed to identify the issue with the connection and fix it.