Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
63 lines (42 sloc) 1.29 KB

#Reverse SSH Tunnel for Raspberry pi


cd ~/.ssh

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

vim config

Host LinuxServer
 Hostname #IP/Hostname of Linux Server
 IdentityFile ~/.ssh/id_rsa
 user #User on Linux Server
 Port #Port on 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 had to install dnsutils for ssh to resolv the hostname (apt-get install dnsutils)

You can’t perform that action at this time.