Remote access via reverse SSH tunnel when there is no access

3Way Solutions Image

Sebastian Misuraca

How many times have you wanted to have SSH access to a server within a company's private network and you have not been able to get the network manager to do a NAT to the SSH port (22) of the required server.

Sometimes due to security policies or configuration inconveniences, they are unable to redirect a public port to port 22 of the server that we want to have access to.

There is a solution, don't be afraid of having to fall into the hands of an unlicensed TeamViewer.

If Muhammad does not go to the mountain, the mountain goes to Muhammad.
There is a possibility to do a reverse SSH (or SSH tunnel).

As?

You only have to access the server once (on the day of installation, or ask someone to run a line) and have the SSH server running from the PC we are trying to connect to, as well as know the public IP.
knowing

To do this, you only need to run an SSH command:

ssh -N -f -R {destination_port}:localhost:22 {our_public_ip}

Ex: ssh -N -f -R 22022:localhost:22 200.142.168.151

This command connects via SSH to our PC (asks for login to our PC) and leaves a tunnel created associated with the localhost of our PC, so that if we later want to connect to that server we can do so with this simple command:

Ex: ssh -p 22022 root@localhost

In this way we have created a constant tunnel to our PC and we can connect without having to redirect any port 22 from the router.

* The server must have Internet output configured correctly.
* The SSH server must be running from the public IP that we are connecting to the Internet.
* Said remote script could be configured at startup with an SSH certificate so that the connection reestablishes itself if the server restarts.

Discover more from 3Way Solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading