SSH Tips I Wish I Knew Earlier
After years of working with remote servers, here are some SSH tricks I use daily.
SSH Config File
Stop typing long commands. Create ~/.ssh/config:
Host dev
HostName 10.0.1.50
User deploy
Port 2222
IdentityFile ~/.ssh/id_ed25519
Now just type ssh dev.
Port Forwarding
Access a remote service locally:
# Forward remote port 5432 (PostgreSQL) to local 15432
ssh -L 15432:localhost:5432 dev
# Now connect locally
psql -h localhost -p 15432 -U postgres
Reverse Tunnel
Expose a local service to the remote server:
# Make local port 3000 accessible on remote as port 8080
ssh -R 8080:localhost:3000 dev
Keep Alive
Add to your ~/.ssh/config to prevent disconnections:
Host *
ServerAliveInterval 60
ServerAliveCountMax 3
Jump Host
Access servers behind a bastion:
Host internal
HostName 192.168.1.100
User admin
ProxyJump bastion
Copy Files Without scp
# Using tar over SSH for directories (faster than scp for many files)
tar czf - ./project | ssh dev "tar xzf - -C /opt/"
These small optimizations add up over time. The SSH config file alone has probably saved me hours of typing.