Helping someone behind NAT with SSH Tunnels

While helping a friend set up a wireless card, I needed to log into his machine. He's behind the typical NAT+router, and describing how to do port forwarding is beyond my interests, here's a simpler way.

Ingredients

You'll need to have SSH installed on the machine you're trying to log into.

In Ubuntu, you can do this by running in a terminal:

sudo apt-get install openssh-server openssh-client

In PLD, you can do this by running:

poldek -i openssh-server openssh-clients
sudo service sshd start

In a terminal on the machine behind the NAT, type ssh -R9022:localhost:22 -l username server, where 9022 is a number over 1024 that's not being used — you might have to try several — and where username is the username on the server and server is the name of the server you can log in to. For me, it looks like this:

ssh -R 9022:localhost:22 -l aredridel polis.nbtsc.org

Log in.

From the helping side, log in to that server from where you're trying to help from. For me:

ssh -l aredridel polis.nbtsc.org

From there, ssh localhost -p 9022 -l username, where 9022 is the port number chosen above that worked, and username is the username on the machine you're ultimately trying to log into. For me:

ssh -p 9022 -l bailey localhost

If everything worked, you will have logged in to the machine and can install or fix things to your hearts content.