This page was exported from Furor Teutonicus [ https://www.furorteutonicus.eu ]
Export date: Mon Dec 17 7:35:52 2018 / +0000 GMT

Reverse SSH tunnel from Hunter to Base


This is my method to keep connected with a remote Raspberry Pi that has a static external IP address and lives behind a NAT, where I don't have control over the router (so no port forwarding). For your use case, you might want to choose another method (there are plenty on the world wide web, I'm sure you can find them), but the simple method below works for me.

on Base


Create a new user with adduser tunnel
user tunnel
pass SomeComplicatedPass

You need a modification to sshd_config. At the end of the file, add a Match block to prevent password-based logins (only allow keybased logins for user tunnel) so the password above is of little use to the outside world ;-)
# Match blocks must be at the and of this config file, see:
# http://unix.stackexchange.com/questions/67334/openssh-how-to-end-a-match-block
Match User tunnel
PasswordAuthentication no

on Hunter


Login to Hunter. I assume evert as your username on Hunter :)

Create the reverse tunnel using:
ssh -N -R 2222:localhost:22 tunnel@Base

Or, more sophisticated:
autossh -M 0 -q -f -N 
-o UserKnownHostsFile=/dev/null
-o StrictHostKeyChecking=no
-o "ServerAliveInterval 60"
-o "ServerAliveCountMax 3"
-R 2222:localhost:22
tunnel@Base

This can be done best by doing it from cron and with a script.
crontab -e
@reboot /home/evert/tunnel.sh 60

My script has a few more tricks (updated 2017-12) and is named tunnel.sh.

You can download my files: reverse_ssh_tunnel.zip

Usage


First login to Base, then connect to Hunter using:
ssh evert@Base
ssh localhost -p 2222

And from there, you can play with Hunter.

Have fun!

Hunter base shot from Mega Man X5
Just a random picture from the internet. "Hunter base shot from Mega Man X5", source: Megaman wikia
Excerpt: How to create a reverse SSH tunnel so you can always login to your remote device.
Post date: 2015-12-27 19:45:14
Post date GMT: 2015-12-27 18:45:14
Post modified date: 2017-12-14 17:40:31
Post modified date GMT: 2017-12-14 16:40:31
Powered by [ Universal Post Manager ] plugin. HTML saving format developed by gVectors Team www.gVectors.com