Reverse ssh tunnel Part 2: Going through Windows


We did a post about reverse ssh tunneling post, which is in spanish (we might redo it in english… or not), so this is part 2.

The main idea of the Part 1 was to make a reverse ssh tunnel to access remotely a server in a private network and the network staff won’t allow us to access it directly.

The issue

Let’s say we have a remote server we want to access (http or ssh) but this server is in a local network and doesn’t have internet access, we will call it Server_1 and its local IP is Then we have our local PC, called Local_PC, which has internet connection and our public IP is If we want to access directly to Server_1 we won’t be allowed since it doesn’t have internet connection.

Tunneling through anything

Then when we need to access the server, the client in the remote network provides us with a Teamviewer connection though a Laptop running windows, what can we do to access directly from our Local_PC running our beloved Linux?

Principle of least effort
The solution


Yes, we can use Putty to make a reverse ssh tunnel from Server_1 to Local_PC, but how do we do so?

You open up Putty in the laptop and go to Connection -> SSH -> Tunnels then you have to input the Source Port which will be Local_Pc:<remote_port> (be sure not to use an already occupied port). Then in Destination we input for ssh or for http or whatever port you need. Change the checkbox from Local to Remote, since we are doing a reverse tunnel, and simply click Add. Finally go back to the Session section and connect to Local_PC via ssh and voilá!

Putty <3 (Note the “Remote” checkbox)

You will be able to access Server_1 from Local_PC simply doing:

ssh user@localhost -p <remote_port>

It is possible to Add more tunnels with a single connection, so you can tunnel an ssh connection and a http one.

Searching words with ‘grep’ in multiple files

One common issue while debugging, refactoring or just programming is when you are searching a word or sentence in a huge number of files and folders.
Several algorithms could be implemented but they always will reach a slow or quick reading of files. One by one until they found a match.

Fortunately GNU provide a powerful tool called ‘grep’. Basically filters the file lines searching a specific word. It uses an algorithm optimized to read files, some say that the real secret it is not to read at all.

This example will show you the matches in the file <filename>.

$ grep "foo" <filename>

Now we go a step ahead by adding some parameters to the ‘grep’ command in order to search in all the files and folders in our location.
$ grep -nHr

Finally this example will show you a list of lines with the file name followed by a number of line and the corresponding line with the match.

$ grep -nHr "frequency"
test/mpeg-freq-test.c:49: struct v4l2_frequency vf;
test/mpeg-freq-test.c:55: vf.frequency = f[cnt % 2] * 16;
test/mpeg-freq-test.c:59: perror("could not set frequency");
doc/ -f Tune to a specific frequency