Tunnels on SSH Connections
Hello everyone, today I will show you a nice trick that we can do with SSH connection, is very useful tip when you need to bind ports of the remote host on your local host.
Basically what the SSH does its bind the port of the remote host on your local machine. So, for example, you want to execute some SQL queries on the server that is running PostgreSQL, but you want use a Graphical Tool do it.
For safety reason, your PostgreSQL port is not opened to the internet, so what you can do is forward the PostgreSQL port to a local port on your machine. And you can achieve this executing this command:
ssh email@example.com -L 5555:localhost:5432
Basically what you doing is binding the 5432 port of the remote host on 5555 port of your computer.
Now you can access the PostgreSQL, using the Graphical tool, just pointing the connection to your machine on the port 5555. Easy Peasy ins’t it? 🙂
Also, you can bind ports of other computer from the network that you are connecting in. For example, you are connecting to a server 192.168.2.100, but you know there is a MySQL running on Server 192.168.2.105, and you want to access it. But how? Just change the localhost to the IP address. Like this:
ssh firstname.lastname@example.org -L 3333:192.168.2.105:3306
Now you can access the MySQL on your 3333 port.
Easy and very useful! Hope you like it.