DevOps / Scripts
bash
Intermediate
Port Forward Tunnel Script
Open an SSH tunnel to forward a remote service port to localhost.
bash
#!/bin/bash
REMOTE_HOST=${1:-bastion.example.com}
REMOTE_PORT=${2:-5432}
LOCAL_PORT=${3:-15432}
ssh -N -L $LOCAL_PORT:localhost:$REMOTE_PORT $REMOTE_HOST &
TUNNEL_PID=$!
echo "Tunnel open: localhost:$LOCAL_PORT -> $REMOTE_HOST:$REMOTE_PORT (PID $TUNNEL_PID)"
echo "Kill with: kill $TUNNEL_PID"
Prerequisites
- ssh
- bastion host access
Pro Tips
- → Add -o ServerAliveInterval=60 to keep idle tunnels open.
Commercial Licensing
Acquire a production access token or template license for enterprise deployment.
Module Info
- Language
- bash
- Level
- Intermediate
- Read time
- 2 min
- Published
- Jul 2026
- License
- Commercial License
Newsletter
New modules every week, directly to your inbox.
Similar Modules
Postgres S3 Backup
Dump a Postgres database, gzip it, push to S3 with AES256 encryption.
bash
·
Intermediate
Disk Usage Alert
Send an alert when any mounted filesystem exceeds a usage threshold.
bash
·
Beginner
Docker Image Cleanup Script
Remove dangling images, stopped containers and unused volumes in one pass.
bash
·
Intermediate