Expose the ssh tunnel port to another machine and automatically detect the script Java code #! /Bin/bash PIDS = 'ps-ef | grep ssh | grep 9222 | awk '{print $2} ''if [-z" $ PIDS "]; then # Check whether the service has enabled ssh-C-f-N-g-R 9222: 127.0.0.1: 22 root@42.121.119.100 echo "start ssh exporter: 'date' ">/home/deploy/autocheck/log.txt else nc-w 3-z 42.121.119.100 9222>/dev/null 2> & 1 if [$? -Ne 0]; then # Check whether the port is connected to kill-9 $ PIDS ssh-C-f-N-g-R 9222: 127.0.0.1: 22 root@42.121.119.100 echo "kill and start ssh exporter: 'date'">/home/deploy/autocheck/log.txt fi because the ssh tunnel is sometimes automatically disabled, therefore, you need to add crontab to check the Java code every minute */1 *****/home/deploy/autocheck/e. sh this script exposes the port 22 of the Local Machine to 9222 of port 42.121.119.100, so that the local machine can be connected through ssh 42.121.119.100-p 9222. Another step is to enable password-free login from the local machine to 42.121.119.100.