The SSH Config File
Instead of remembering IP addresses and usernames for every server, use the SSH config file to create shortcuts.
Create the Config
Edit ~/.ssh/config:
Host web-server
HostName 198.48.63.241
User deploy
Port 22
IdentityFile ~/.ssh/id_ed25519
Host db-server
HostName 198.48.63.242
User admin
Port 2222
IdentityFile ~/.ssh/db_key
Host staging
HostName 67.231.246.194
User root
IdentityFile ~/.ssh/staging_key
ForwardAgent yesUsage
# Instead of:
ssh -i ~/.ssh/id_ed25519 -p 22 deploy@198.48.63.241
# Just type:
ssh web-serverUseful Options
| Option | Purpose |
|---|---|
HostName | Server IP or domain |
User | Login username |
Port | SSH port |
IdentityFile | Path to private key |
ForwardAgent | Forward SSH agent (for git through jumpbox) |
ProxyJump | Jump through a bastion host |
ServerAliveInterval | Keep connection alive |
Wildcard Patterns
# Apply settings to all hosts
Host *
ServerAliveInterval 60
ServerAliveCountMax 3
AddKeysToAgent yes
# Apply to hosts matching pattern
Host prod-*
User deploy
IdentityFile ~/.ssh/prod_keyJump Hosts
Host bastion
HostName 198.48.63.240
User admin
Host internal-server
HostName 10.0.0.5
User deploy
ProxyJump bastion# Connects through bastion automatically
ssh internal-serverSCP and rsync
SSH config aliases work with all SSH-based tools:
scp file.txt web-server:/var/www/
rsync -avz ./dist/ web-server:/var/www/html/