Reputation: 61
I have database server on AWS and from my PC i have to access that database using ssh tunneling for below scenario.
PC --> Jump1 [x.pem, port:22] --> Jump2 [y.pem, port:443] --> mysqldb:3306
Upvotes: 2
Views: 1913
Reputation: 538
If you already have your public keys in authorized_keys on respective hosts
then you can use -J
directive.
like this:
ssh -J user1@host1 user2@host2
If you have more than one jump host you can concatenate it inside of -J
directive like this:
ssh -J user1@host1,user2@host2,user(n-1)@host(n-1) userN@hostN
I also using port forwarding so it takes your port data all the way to the last site and then connect to specific site like this:
ssh -L 8080:microsoft.com:80 -J user1@host1 user2@host2
It will create unencrypted connection only from host2 to microsoft.com:80
Upvotes: 1
Reputation: 61
For this kind of scenarios, Config File is the best way to do it.
Run
$ touch ~/.ssh/config
Add host entries in a config file.
Host <Host_Name>
HostName <URL/IP of Jump2>
User <>
Port <>
Identityfile <yyy.pem>
StrictHostKeyChecking no
ProxyCommand ssh -i <xxx.pem> <user>@<IP/DNS of Jump1> nc %h %p 2> /dev/null
and then to create a tunnel
$ ssh <local_port>:DB_URL:<DB PORT> <Host_name>
that's it. Now you can connect to DB using
localhost:<local_port>
Upvotes: 2