All Snippets

SSH Tunnel Patterns

Common SSH port forwarding patterns for accessing remote databases, dashboards, and services securely.

SSH tunnels let you securely access remote services as if they were local. Three patterns cover most use cases.

Local forward: access remote service on localhostbash
1
# Access remote PostgreSQL (port 5432) on localhost:15432
2
ssh -L 15432:localhost:5432 user@bastion-host
3
 
4
# Access a dashboard behind a firewall
5
ssh -L 8080:internal-dashboard:80 user@jump-server
Remote forward: expose local service to remote hostbash
1
# Make your local port 3000 available on remote host's port 9000
2
ssh -R 9000:localhost:3000 user@remote-server
Dynamic (SOCKS proxy)bash
1
# Create a SOCKS5 proxy on localhost:1080
2
ssh -D 1080 user@remote-server
3
 
4
# Then configure your browser/app to use SOCKS5 proxy at localhost:1080

Add -N to skip opening a shell (tunnel only) and -f to background it: ssh -NfL 15432:localhost:5432 user@bastion.