Local Port Forwarding
Forward a port on your local machine to a port on the remote server (or a machine accessible from the remote server).
# Access remote MySQL (3306) via local port 3307
ssh -L 3307:localhost:3306 user@server
# Then connect locally
mysql -h 127.0.0.1 -P 3307 -u rootRemote Port Forwarding
Make a local service accessible from the remote server:
# Expose local port 3000 on the server port 8080
ssh -R 8080:localhost:3000 user@serverDynamic SOCKS Proxy
# Create a SOCKS5 proxy on local port 1080
ssh -D 1080 user@server
# Configure your browser to use SOCKS5 proxy at localhost:1080
# All traffic routes through the serverPersistent Tunnels
# Keep tunnel alive with autossh
sudo apt install -y autossh
autossh -M 0 -f -N -L 3307:localhost:3306 user@serverSSH Config for Tunnels
# ~/.ssh/config
Host db-tunnel
HostName server-ip
User deploy
LocalForward 3307 localhost:3306
ServerAliveInterval 60
# Then just: ssh -N db-tunnel