snippetssh-configTippending
SSH Config File for Streamlined Connections
Viewed 0 times
SSH configbastionjump hostProxyJumpport forwardingtunnel
Problem
Typing full SSH commands with host, user, port, and key file every time is tedious and error-prone. Jump hosts make it worse.
Solution
Configure ~/.ssh/config for named connections:
``
``
ssh-config
# ~/.ssh/config
# Basic host alias
Host prod
HostName 203.0.113.10
User deploy
Port 2222
IdentityFile ~/.ssh/prod_key
# Now just: ssh prod
# Jump host (bastion)
Host bastion
HostName bastion.example.com
User admin
IdentityFile ~/.ssh/bastion_key
Host internal-db
HostName 10.0.1.50
User dbadmin
ProxyJump bastion
LocalForward 5433 localhost:5432
# ssh internal-db -> connects through bastion
# Also forwards local port 5433 to remote PostgreSQL
# Wildcard for AWS instances
Host *.compute.amazonaws.com
User ec2-user
IdentityFile ~/.ssh/aws_key
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
# Keep connections alive
Host *
ServerAliveInterval 60
ServerAliveCountMax 3
AddKeysToAgent yes
IdentitiesOnly yes
# Multiple GitHub accounts
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/personal_key
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/work_key
# Usage: git clone github-work:org/repo.git
`
Useful options:
ControlMaster auto + ControlPath = reuse connections (faster)ProxyJump = multi-hop (replaces ProxyCommand)LocalForward = tunnel remote ports locallyRemoteForward` = expose local ports on remoteWhy
SSH config replaces aliases and scripts with a standard, portable configuration. New team members can copy the config and immediately connect to all servers.
Gotchas
- File permissions must be 600 (chmod 600 ~/.ssh/config) or SSH ignores it
- IdentitiesOnly yes prevents SSH from trying all keys (important with many keys)
Context
Streamlining SSH connections to multiple servers
Revisions (0)
No revisions yet.