## Port
ssh -p 4567 apollo@example.com
## keep alive
ssh -o ServerAliveInterval=600 lake@4XXXXXXX3
## Tunnel 9902 at server Remote side
(10.0.0.4 is in the same network of ssh client, behind a firewall, 4XXXXXXX3 is SSH server IP address on public Internet )
ssh -R 9902:10.0.0.4:22 lake@4XXXXXXX3
### run tunnel in background
ssh -C -f -N -R XXXX
[lake@lake_centos7 ~]$ cat sshtunnel.sh
#!/bin/bash
user=$USER
while true;
do
echo check if $user has stared already
pid=`ps -ef|grep ssh |grep $user|grep ServerAliveInterval |awk '{print $2}'`
if [ ! -n "$pid" ] ;then
echo start ssh tunnel now
ssh -C -f -N -o ServerAliveInterval=600 -R 9902:10.0.0.4:22 lake@4XXXXXXX3
else
echo already start in $pid
echo sleep now
sleep 5m
fi
done
[lake@lake_centos7 ~]$