Remote connection to MySQL database via secure SSH tunnel

Advantages of the solution

Since the remote connection to the MySQL database used by the Remote MySQL Database function available in cPanel is unencrypted by default, we recommend using an SSH tunnel. This will allow us to connect to the base within a secure encrypted SSH transmission.

There is also no need to specify your IP in cPanel, as before in the “Remote MySQL Database” solution

What will it take?

In order for us to connect to our account via SSH, we will need to enable SSH access for our account, via Customer Area: https://www.smarthost.pl/panel/login

https://www.smarthost.au/panel/login

Expand the details of the hosting account with the magnifying glass icon, and then click the Enable SSH button.

Remember to create a database beforehand, a database user, and assign this user to the database by giving him the appropriate permissions. All this is done through cPanel. For more information, see the guide:

https://www.smarthost.au/blog/how-to-set-up-a-new-mysql-database

A guide for Windows, using PuTTY utility

We will use PuTTY to create the tunnel – it is free and can be downloaded from the website:

https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

Install and run the program.

Type our cPanel login in the first field, then @, then the name of your Smarthost account. In the second field, enter port 5739.

From the menu on the left, expand SSH by clicking the square with +. Additional options unfold, from which we choose Tunnels. Type in the values as in the image below, select IPv4 and click Add. Finally, we click Open (we can also go to the initial Session screen and save our settings).

A console window will appear, asking us to enter a password – we enter the password as the one for cPanel. We do not close this window as long as we keep connecting to the base.

To connect to the database now, all you need to do is specify the host address on your computer: localhost and the standard MySQL port: 3306

The second way is to use the command line where you type the command:

ssh -L 3306:localhost:3306 login@client-name.smarthost.eu -p 5739

A guide for Linux and macOS, using the ssh command

We type the command:

ssh -L 3306:localhost:3306 login@client-name.smarthost.eu -p 5739

where instead of login we specify our cPanel login, and instead of client-name.smarthost.eu we specify our account root domain.

You will be asked to enter a password, once entered, the tunnel will be active until you close the connection with the exit command.

To connect to the database now, all you need to do is specify the host address on your computer: localhost and the standard MySQL port: 3306

Leave a Reply