Trace: ssh_tunneling

SSH tunneling

The problem

I have several Raspberry Pi (RPi) in my home, I have 1 MB connection with MiFi modem. I can ask to my operator to get an public IP address or get open ports, I spent a lot of time out of my home, but I want get access to all my RPi.

I checked that some partners of work and friends uses a lot of third party services to get access their RPi, lot of lammers! I don't want depend of third party services and get off my privacy.

I read about SSH tunneling, I have time to play and this is my result.

I little diagram about my scenario:

My solution

I have one VPS for my personal stuff. I have hosted this web page and Nextcloud, some monitoring tools and other stuff, please don't hack me.

I can make a SSH tunneling from my RPi to my VPS so I can enter to my VPS from any place in the world and get access to my RPi.

Follow this steps to start a test, enter to your RPi and create the tunneling, for example:

ssh -R 2210:localhost:22 [email protected] -p 22

You need change the parameters to fit with your scenario. Now you can enter to your VPS and enter the next command:

ssh -p 2210 youruser@localhost

And you get access to your RPi.

The problem is if you closes the terminal, you will finish the SSH session, you need execute the next command to put in background the SSH tunneling:

ssh -N -f -R 2210:localhost:22 [email protected] -p 22

You still having problems, the server will ask the password, you need generate ssh keys to stop asking passwords, please follow this steps in RPi as “youruser”. Answer the questions, generally is default option but please doesn't configure a password.

ssh-keygen
ssh-copy-id -p 22 estebanmonge.tk

You can how verify that you can make a SSH without enter password. Now you can make the SSH tunneling without password.

Troubleshooting

If the connection fails and when you make a new connection you received this message: “Warning: remote port forwarding failed for listen port”, you need kill the process in the VPS server, follow this steps:

$ netstat -nlp | grep :2210

Check the process ID and kill it:

$ kill $PID

You can avoid that the SSH session still running in VPS if fails in RPi adding in the file /etc/ssh/ssh_config of your RPi and VPS the next line:

ExitOnForwardFailure yes

References

Credits

ssh_tunneling.txt · Last modified: 2016/09/05 00:11
Public Domain Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain