Skip to content

Instantly share code, notes, and snippets.

@germanramos
Last active Dec 31, 2015
Embed
What would you like to do?
Create SSH tunnels

#On the client: sudo ssh-keygen -f /root/topicTunnel.pem #On the Server: sudo useradd -m -s /bin/false tunnel
sudo -u tunnel bash
cd /home/tunnel
mkdir .ssh
chmod 700 .ssh
###Copy the content of client generated .pub file in server authorized_keys file:
nano /home/tunnel/.ssh/authorized_keys
#On the client:

###Test: sudo bash
nc -z localhost 16379 || ssh -i /root/topicTunnel.pem -N -L 16379:localhost:6379 tunnel@listener1.topicthunder.io
###Automatize (Also see autossh): 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 tunnel@listener1.topicthunder.io &
          • 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 tunnel@listener2.topicthunder.io &
          • 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 tunnel@listener3.topicthunder.io &

#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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment