Managing services on AWS instance thru SSH tunnels

There are ways to connect and manage services on your AWS instance using tunnels, assuming you already have a connection to your instance via SSH.
For Bitnami instances, you can find detailed instructions here.
I assume this should work for any Linux-based instances.

But why limit yourself to just SSH if you can go further and configure tunneling, which will allow you to connect to any service running on that instance from your local machine?

Here is an example for a MySQL connection and the WordPress admin console.
There are many different tools to configure SSH and tunneling. In this example, I will use PuTTY.

 

What are we doing?

Lets assume you configured the session and the key

Now it is time to configure your tunnels.

In the example above, I have configured local port 8888 to be forwarded to remote port 80, and local port 3386 to be forwarded to remote port 3306. So, what will happen is that every time you make a call to localhost:8888 on my computer, information will be sent to AWS instance port 80 through the SSH tunnel. The same applies to ports 3386 and 3306.

Now you can open the connection.

Why is this convenient?

Because now you can do this in your browser:

You can use the WordPress admin console without exposing it to the rest of the world.

You can also connect to your MySQL instance from your local machine and run SQL queries using your favorite IDE, as demonstrated below.

Overall, tunneling can be applied to many other use cases.

Where else this approach can be applicable?

This subject is not limited to AWS. SSH tunneling is widely used approach. Pretty much any Linux machine or VM can me managed this way.