My setup:
- EC2 instance within a private subnet that has a MySQL database
- EC2 instance within a public subnet that I use as bastion (jump host)
I'm able to login with SSH from the bastion host to the host in private subnet after following the instructions from https://digitalcloud.training/ssh-into-ec2-in-private-subnet/
But, I would like to access the MySQL database hosted on the instance that has the private subnet from local softwares (TablePlus, Tableau...). I've been trying to do a SSH tunnel but without success.
Here's the command line I've been using:
ssh -A ubuntu@ec2-xxx-xxx-xxx-xxx.us-west-2.compute.amazonaws.com -L 3307:ubuntu@xxx.xxx.xxx.xxx:3306 -N -f -v
This is my testing:
➜ ~ lsof -i4 -P | grep -i "listen" | grep 3307
ssh 95829 wild 8u IPv4 0x35f42fb5d0e0a22b 0t0 TCP localhost:3307 (LISTEN)
➜ ~ nc -zv 127.0.0.1 3307
Connection to 127.0.0.1 port 3307 [tcp/opsession-prxy] succeeded!
➜ ~ mysql -h 127.0.0.1 -P 3307 -u my-username -p
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
And here's the response I'm getting on the server:
debug1: Connection to port 3307 forwarding to ubuntu@xxx.xxx.xxx.xxx port 3306 requested.
debug1: channel 2: new [direct-tcpip]
channel 2: open failed: connect failed: Name or service not known
debug1: channel 2: free: direct-tcpip: listening port 3307 for ubuntu@xxx.xxx.xxx.xxx port 3306, connect from 127.0.0.1 port 59686 to 127.0.0.1 port 3307, nchannels 3