Reverse Tunneling to access local desktop remotely
I work from a co-working office and it has a shared internet connection. I wanted to access my office desktop from my home. Though there are multiple apps to do this, I only needed ssh access, so I did it the old way.
I spin up a tiny server. I used AWS micro instance. Lets call it server
. Lets call my desktop as local-desktop
and I will be using my home desktop (let’s call it remote-desktop
) to connect to local-desktop
through server
.
Step 1:
local-desktop
connects to server
and forward remote port 8022
to its local port 22
using command.ssh -R 8022:localhost:22 user@server #run it in local-desktop
Where -R
is for remote port forwarding, 8022
is server
’s port which will be mapped to port 22
of local-desktop
Now, if you ssh into the server
server and run ssh user@localhost -p 8022
you will be able to access local-desktop
Step 2:
I don’t want to login into server
server every time to access my local-desktop
. That’s why I setup a forward proxy to map my remote-desktop
‘s port 9922
to server
‘s port 8022
which is already mapped to local-desktop
‘s port 22
.
Here is a command to do that: ssh -L 9922:localhost:8022 user@server #run it in remote-desktop
Now I can login to my local-desktop
from my remote-desktop
using command ssh user@localhost -p 9922
.