General scripts and aliases I use in my linux environments
To run applications as system service
- Install autossh with
sudo apt install autossh
- Create service file
sudo nano /etc/systemd/system/tunnel-service.service
- Paste the following, where 9997 is remote port and cakes is the remote host config in ~/.ssh; make sure you put your specified user
[Unit]
Description="SSH Reverse Tunnel Service"
After=network-online.target ssh.service
[Service]
Type=simple
User=pi
Restart=always
RestartSec=5
ExecStart=/usr/bin/autossh -M 0 -o ExitOnForwardFailure=yes -N -R 9997:localhost:22 cakes
[Install]
WantedBy=multi-user.target
- Install service with
sudo systemctl enable tunnel-service.service
- Start service with
sudo systemctl start tunnel-service.service
- From your remote computer, ssh into the reversed tunnel computer by
ssh user@localhost -p 9997