Auto SSH reverse tunnel into AWS with raspberry pi

Borrowed from: https://www.tunnelsup.com/raspberry-pi-phoning-home-using-a-reverse-remote-ssh-tunnel/

1) Setup Free Tier AWS instance
2) Download user_hostname.pem SSH key

(on pi)
Copy user_hostname.pem to ~/ on pi

vi create_ssh_tunnel.sh

#!/bin/bash
createTunnel() {
  /usr/bin/ssh -i user_hostname.pem -N -R 2222:localhost:22 user@aws-dns-hostname
  if [[ $? -eq 0 ]]; then
    echo Tunnel to jumpbox created successfully
  else
    echo An error occurred creating a tunnel to jumpbox. RC was $?
  fi
}
/bin/pidof ssh
if [[ $? -ne 0 ]]; then
  echo Creating new tunnel connection
  createTunnel
fi

crontab -e
*/1 * * * * ~/create_ssh_tunnel.sh > tunnel.log 2>&1

sudo /etc/init.d/crontab reload
(end on pi)

(on aws)
echo “ssh -p 2222 user@localhost” > connect
(end on aws)

change 2222 for each pi added to the “network”.