Skip to content

Instantly share code, notes, and snippets.

@pandeybk
Last active June 20, 2016 16:29
Show Gist options
  • Save pandeybk/e32f7551ca7a61b6c8fb958b70a855e1 to your computer and use it in GitHub Desktop.
Save pandeybk/e32f7551ca7a61b6c8fb958b70a855e1 to your computer and use it in GitHub Desktop.
Create reverse tunnel using autossh, add pub keys using password base authenication
TUNNEL_PORT1=$1
TUNNEL_PORT2=$2
wget http://www.harding.motd.ca/autossh/autossh-1.4e.tgz
gunzip -c autossh-1.4e.tgz | tar xvf -
cd autossh-1.4e
./configure
make
sudo make install
sudo apt-get install sshpass
ssh-keygen -f /home/user/.ssh/autossh_rsa -t rsa -C `hostname` -N ''
cat <<EOF>/home/user/.ssh/autossh.sh
/usr/local/bin/autossh -i /home/user/.ssh/autossh_rsa -M 2$TUNNEL_PORT1 -f -N [email protected] -R $TUNNEL_PORT1:localhost:22 -C &
/usr/local/bin/autossh -i /home/user/.ssh/autossh_rsa -M 2$TUNNEL_PORT2 -f -N [email protected] -R $TUNNEL_PORT2:localhost:22 -C &
EOF
chmod 755 /home/user/.ssh/autossh.sh
crontab -l | { cat; echo "@reboot /home/user/.ssh/autossh.sh"; } | crontab -
sshpass -p 'password' ssh-copy-id -i /home/user/.ssh/autossh_rsa.pub [email protected]
sshpass -p 'password' ssh-copy-id -i /home/user/.ssh/autossh_rsa.pub [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment