How to keep ssh connection alive ?
While working remotely using ssh, you may have experienced ssh connection is closed (disconnected) while you are out for a tea or when you leave sshconnection inactive for few mins. It is very annoying that ssh connection getting disconnected again and again. Here is script which help you to keep ssh connection alive.
Executing following script to keep your ssh connection alive. This script will keep executing commands hostname and date every after 60 seconds so your ssh connection will never inactive more than 60 secs.
Edit the file keepalive.sh using vi editor and add following lines in the same.
[root@linuxserver ~]#vi keepalive.sh
#!/bin/sh
if [ $# -eq 1 ]; then
sleep_time=”$1″
else
sleep_time=60
fi
while true; do echo "`hostname` `date`"; sleep $sleep_time;done
now execute it as given below
[root@linuxserver ~]#sh keepalive.sh 60
When you will return to your work you can terminate this running script by pressing ctrl + c.













