Skip to content

Instantly share code, notes, and snippets.

@ledangtuanbk
Last active November 14, 2019 03:08
Show Gist options
  • Save ledangtuanbk/3e147d08c9ea9f1f3716b42ee48f82e4 to your computer and use it in GitHub Desktop.
Save ledangtuanbk/3e147d08c9ea9f1f3716b42ee48f82e4 to your computer and use it in GitHub Desktop.
How to use ssh_tunnel
1. Connecting to a database behind a firewall
ssh -L 9000:localhost:5432 user@example.com database postgres run port 5432 only access from localhost
2. Remote port forwarding
ssh -R 9000:localhost:3000 user@example.com
Localhost running port 3000 and want to acess from internet port 9000
- set GatewayPorts yes in /etc/ssh/sshd_config
- this can be done by autossh
autossh -M 0 -f -q -N -o "ServerAliveInterval 5" -o "ServerAliveCountMax 1" -o "ExitOnForwardFailure yes" -R 0.0.0.0:[SERVER]:localhost:[CLIENT_IP] [SERVER_USER]@[SEVER_IP]
- remember to run on reboot
@reboot /root/ssh_tuner.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment