#On the client:
sudo ssh-keygen -f /root/topicTunnel.pem
#On the Server:
sudo useradd -m -s /bin/false tunnel
###Copy the content of client generated .pub file in server authorized_keys file:
sudo -u tunnel bash
cd /home/tunnel
mkdir .ssh
chmod 700 .ssh
nano /home/tunnel/.ssh/authorized_keys
#On the client:
###Test:
sudo bash
###Automatize (Also see autossh):
nc -z localhost 16379 || ssh -i /root/topicTunnel.pem -N -L 16379:localhost:6379 [email protected]
sudo crontab -u root -e
-
-
-
-
- nc -z localhost 16379 || ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ServerAliveInterval=30 -o ServerAliveCountMax=4 -i /root/topicTunnel.pem -N -L 16379:localhost:6379 [email protected] &
-
-
-
-
-
-
-
- nc -z localhost 26379 || ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ServerAliveInterval=30 -o ServerAliveCountMax=4 -i /root/topicTunnel.pem -N -L 26379:localhost:6379 [email protected] &
-
-
-
-
-
-
-
- nc -z localhost 36379 || ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ServerAliveInterval=30 -o ServerAliveCountMax=4 -i /root/topicTunnel.pem -N -L 36379:localhost:6379 [email protected] &
-
-
-
#References: https://support.asperasoft.com/entries/20150692-Set-up-permanent-SSH-tunnel-via-cron http://webdevwonders.com/configuring-a-permanent-ssh-tunnel-for-mysql-connections-on-debian/ http://www.brandonchecketts.com/archives/creating-a-permanent-ssh-tunnel-between-linux-servers