sshssh-tunneltunneling

SSH tunnel to Database from two level of jump server with different keys


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


Solution

  • 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>