Home

Debian/Ubuntu Tips & Tricks

Debuntu.org: .deb packages, Unix/Linux Tutorials and Articles.

User login

Get Firefox


Tips


How To Connect to a remote mysql server using mysqlcc and ssh tunneling.

This will explain how to connect to a remote mysql server only allowing connections from locahost, from your computer in a secure way as it is being done through a ssh tunnel.

What we are going to do here is to create a tunnel from your localhost to your remote host (the one the sql and ssh servers are running on).

If your sql server and ssh server runs on different machines, please read on and then refer to How To: Connect to a remote mysql server using mysqlcc and ssh tunneling part 2

This tunnel allow you to have a secure connection from your computer to the remote host.

First of all, we are going to configure ssh. Edit or Create file ~/.ssh/config. Add the following lines (depending on your settings):

Host myhostnickname

Hostname myremotehost.com

User mysshuser Localforward 3307 localhost:3306

#only if using rsa or dsa key authentification

IdentityFile ~/.ssh/myremotehost_id_dsa

connect to your remote host

$ssh myhostnickname

This way, when you connect to your remote host via ssh, you create a tunnel which allow you to communicate from your local computer port 3307 to the remote machine on port 3306. For the remote host, it is like you were communicating on localhost port 3306.

In mysqlcc, create a new connection (Ctrl+N). Give it the name you like to describe it, set hostname to 127.0.0.1 (not localhost... it seems mysqlcc can't recognize localhost as 127.0.0.1), set username to your remote username, same with password. As we have created a tunnel from port 3307 to 3306, mysqlcc is going to connect on port 3307 so set port to 3307.

You are done, you can now connect to a remote mysql server accepting only local connections from your computer and all this in a secure way.


what if i don't know about

what if i don't know about the Hostname? is it possible to replace it with IP?


Yes, Sure you can, this is

Yes,
Sure you can, this is usually easier to remember a hostname ;) but IP will do.

Debuntu


mysql not mysqlcc ?

what if i want to connect using normal mysql prompt is it possible?


It works the same way. You

It works the same way.
You want to type a command such as:
$ mysql -h 127.0.0.1 -P 3007 -u username -p database_name
Debuntu


ssh

"First of all, we are going to configure ssh. Edit or Create file ~/.ssh/config"
Where is this file located? I'm a total newbie.
Thanks!


This file is at

This file is at ~/.ssh/config
You will have to create it if it is not there. Mind that the ~ stands for home directory so if your user is named foo, it should be /home/foo/.ssh/config .
to create it, you might have use gedit instead of vim which will make things more user friendly. Don't forget to show hidden files when you browse your filesystem in order to be able to save your file in /home/foo/.ssh/config .
Debuntu