Reverse SSH Tunnel
raspberry pi reverse ssh tunnel for conecting to a linux server


cd ~/.ssh

ssh-keygen -t rsa #no password and the default file name

vim config

Host LinuxServer
 Hostname #IP/Hostname of the Linux Server
 IdentityFile ~/.ssh/id_rsa
 user #User on the Linux Server
 Port #Port on the Linux Server for OpenSSH
 TCPKeepAlive yes
 #ForwardX11Trusted yes #only if needed

scp LinuxServer:~/.ssh/authorized_keys



createTunnel() {
  /usr/bin/ssh -N -R 2222:localhost:22 LinuxServer //if OpenSSH server port for the Pi is 22
  if [[ $? -eq 0 ]]; then
    echo Tunnel to jumpbox created successfully
    echo An error occurred creating a tunnel to jumpbox. RC was $?
/bin/pidof ssh
if [[ $? -ne 0 ]]; then
  echo Creating new tunnel connection

sudo chmod 700 ~/

crontab -e

#Make the raspberry pi connect back to a Linux Server every day between 20 and 21.
#On the Linux server run "ssh -l PiUser -p 2222 localhost"
*/1 20 * * * ~/ > tunnel.log 2>&1

on my raspberrypi I had to install dnsutils for ssh to resolv the hostname (apt-get install dnsutils)

Posted on:

May 2, 2014
172 words

Contact Me:

If you are interested in contacting me feel free to do so by mail or online:

nob {at}