bashbeginner

SSH Config for Server Management

Organized SSH config file with host aliases, jump hosts, and connection multiplexing for DevOps.

bash
# ~/.ssh/config

# Global defaults
Host *
    ServerAliveInterval 60
    ServerAliveCountMax 3
    AddKeysToAgent yes
    IdentitiesOnly yes
    ControlMaster auto
    ControlPath ~/.ssh/sockets/%r@%h-%p
    ControlPersist 600

# Production servers
Host prod-web
    HostName 10.0.1.10
    User deploy
    IdentityFile ~/.ssh/prod_key
    Port 22

Host prod-db
    HostName 10.0.1.20
    User dbadmin
    IdentityFile ~/.ssh/prod_key
    LocalForward 5433 localhost:5432

# Staging through jump host
Host staging-*
    ProxyJump bastion
    User ubuntu
    IdentityFile ~/.ssh/staging_key

Host bastion
    HostName bastion.example.com
    User ops
    IdentityFile ~/.ssh/bastion_key

Host staging-web
    HostName 172.16.1.10

Host staging-worker
    HostName 172.16.1.11

# Quick commands:
# ssh prod-web                    # Connect to production
# ssh -N prod-db                  # Port forward only
# ssh staging-web                 # Auto-jumps through bastion
# mkdir -p ~/.ssh/sockets         # Required for ControlPath

Use Cases

  • Managing connections to multiple servers
  • Secure database access via SSH tunneling
  • Team SSH configuration standardization

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.