Last active
April 19, 2019 07:31
-
-
Save wwwins/1d83eb1583fdfa524f745a60e1601618 to your computer and use it in GitHub Desktop.
setup reverse ssh tunnel with cron
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# add the following job into crontab | |
# */5 * * * * /usr/local/bin/autossh.sh | |
IP="1.1.1.1" | |
/bin/ping -c 3 $IP > /dev/null | |
if [ $? != 0 ] | |
then | |
exit 1 | |
fi | |
#SSH_COMMAND="ssh -f -N -R 12322:localhost:22 -p 2222 [email protected]" | |
SSH_COMMAND="ssh -f -N -R 12322:localhost:22 -i $HOME/.ssh/id_rsa [email protected]" | |
cnt=$(ps -aux | grep -v "grep" | grep -c "$SSH_COMMAND") | |
if [[ $cnt < 1 ]] | |
then exec $SSH_COMMAND | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cat << EOF >> ~/.ssh/config | |
Host * | |
ServerAliveInterval 30 | |
ServerAliveCountMax 5 | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment