Creating SSH Tunnel From Linux or MacOS

Creating SSH Tunnel From Linux or MacOS

To create a ssh tunnel, Please follow the below steps: Use the following command to create a ssh tunnel.
$ ssh -L 3306:127.0.0.1:3306 username@server.com username@server's password:
We are creating SSH tunnel from local port 3306 from our computer to port 3306 on server.com. We can use both localhost or 127.0.0.1 To create a tunnel we can use -NnT option. We only need to add -NnT option after the above command
$ ssh -L 3306:127.0.0.1:3306 username@server.com -NnT
To create an SSH Tunnel to a server behind server.com other than our local computer we only need to change -L option to -R and also change 127.0.0.1 to the remote MySQL server IP Address or hostname. For example :
$ ssh -R 3306:192.168.1.1:3306 username@server.com (or) $ ssh -R 3306:192.168.1.1:3306 username@server.com -NnT
After creating the tunnel, Please open another tab or window on your terminal app. Then you can test connecting to MySQL on the remote server by using below command.
$ mysql -u root -p --port 3306 -h 127.0.0.1 Enter password:
Then you will be able to connect MySql
mysql>
While checking we need to specify host with -h and put 127.0.0.1 instead of localhost since MySql will try to connect to the local MySQL socket on your computer instead of the TCP connection via port 3306.
    • Related Articles

    • Creating Tunnel From Windows Using PuTTY

      What is PuTTY? PuTTY is an SSH and telnet client, developed originally by Simon Tatham for the Windows platform. PuTTY is open source software that is available with source code and is developed and supported by a group of volunteers. Please find the ...
    • Set-up SSH keys

      Introduction: Setting up SSH based security to access your server is a much more effective way than the use of a manual root password. Cracking the security system of a VPS depending on SSH keys is nearly impossible since it secures your VPS in a ...
    • Creating server disk image backup

      Creating a server template can prove to be an important feature to have and therefore we provide you with this option with a seamless interface using which you can create a template of your server with just one-click operation. Let's look at a couple ...
    • Disabling reverse dns lookups in ssh

      Sometimes it is very annoying to wait ten's of seconds to finish remote ssh server's reverse dns lookup procedure. Steps to disable 1. Open configuration file /etc/ssh/sshd_config. 2. Find UseDNS directive and set value to no. 3. In case this ...
    • SSH::Generating a Key Pair for MAC

      Generating SSH keys on Mac OS X The following outlines the process of setting up key-based SSH login on Mac OS X and Mac OS X Server. To set up key-based SSH, you must generate the keys the two computers will use to establish and validate the ...