How To Raspberry Pi

Use to access your Raspberry Pi from internet

A Raspberry Pi

Supercharging your SSH by automating connection and startup

Now that your website is ready, you will need to run the SSH command every couple of hours and also each time Raspberry Pi restarts. To fix this we are going to:

a) Build a script using autossh
b) Start the script on startup

a) Build a script using autossh

We first install autossh from the Raspberry Pi repository by running the command.

sudo aptitude install autossh -y

Next We create a file that we will use to enter the scripts to run at startup, type


Then add this line to the file.

function localtunnel {
autossh -i /home/pi/mysiteKeyPair -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -R -R
until localtunnel; do
echo "local tunnel crashed"
sleep 2

Then save and exit.

In the command above we are requesting two tunnels, one to, the other to

For more details you can always read this guide about ssh tunneling.

Now we need to make out script an executable, so we run the following

sudo chmod +x
Statup script owner and permissions
Making the script executable
b) Start the script on startup

There are several ways to do this, but what works for me is to see the commands on the terminal. To do that we first edit the autostart file.

sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart

Insert this line at the bottom, then save and exit.

@lxterminal -e /home/pi/
LXDE Autostart to start a terminal with script running
LXDE Autostart

Next time you restart your raspberry pi the site will still be accessible.

That’s it. Let us know your thoughts / issues in the comments below.
ALSO READ  [VIDEO] How To: Microsoft Sticky Notes Cloud Sync

Leave a Reply

Notify of