Reverse shell with ssh
- May 3rd, 2011
- Write comment
- The machine you want to access is running ssh daemon, listening on port 2200
- The address of such machine is irrelevant since it is unreachable.
- The machine you have access to is also running ssh daemon, e.g., listening on port 2201
- Such machine has instead a reachable address, such as 6.6.6.6
Now, of course the first thing you have to do is reach the machine with public address from the machine behind the firewall or NAT and establish a connection to be used eventually as channel to forward the ssh connection. The following command does that via ssh, and tells the machine to forward any connection incoming on its port 2202 to localhost:2200 from the command issuer point of view.
ssh -p 2201 -NR 2202:localhost:2200 user@6.6.6.6
At this point you probably got it, you can access your home box by ssh’ing into 6.6.6.6 and then running the following command to access the other machine.
ssh -p 2202 user@localhost
It might also be nice to filter port 2202 from all sources except localhost, just in case your private box is not hardened as much as your public machines
Ok, this can be found pretty everywhere on the internet, but on the n-th time someone asked me how to use management scripts that do stuffs via SSH without have to enter one or more password, I need to write it here so that next time I’ll have no remorse in saying “go read it online, on my website”.
There are several ways to change the keyboard layout in linux.

