Issue
I'm using reverse ssh for connecting to remote client , Operator run reverse one time and leave client system how can i write bash script , when reverse ssh disconnected from server retry to connect to server (ssh)
Solution
Use autossh. Autossh "automatically restart[s] SSH sessions and tunnels"
sudo apt-get install autossh
I use autossh to to keep open reverse tunnel that I depend on. It works very well, even with long periods of lost connection.
Here is the script I use to create the tunnel:
#!/bin/bash
AUTOSSH_GATETIME=0
export AUTOSSH_GATETIME
autossh -f -N -R 8022:localhost:22 username@host -o "ServerAliveInterval 45" -o "ServerAliveCountMax 2"
I execute this script at boot with this cronjob:
@reboot /home/scripts/./persistent-tunnel.sh
Answered By - Jake Answer Checked By - Clifford M. (WPSolving Volunteer)