SSH Cheatsheet
The Config File
Use this SSH reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.
Overview
~/.ssh/config lets you alias hosts and set per-host options so you type ssh prod instead of ssh -p 2222 -i ~/.ssh/deploy_key pablo@203.0.113.5.
chmod 600 ~/.ssh/config # required — SSH ignores world-readable configs
Structure
# Global defaults — apply to every host Host * ServerAliveInterval 60 ServerAliveCountMax 3 AddKeysToAgent yes IdentityFile ~/.ssh/id_ed25519 # A named alias Host prod HostName 203.0.113.5 User deploy Port 2222 IdentityFile ~/.ssh/deploy_ed25519 # Wildcard alias Host *.internal User ubuntu ProxyJump bastion
Rules are read top-to-bottom; the first matching value wins. Put specific hosts before Host *.
Common Directives
| Directive | Default | What it does |
|---|---|---|
HostName | (alias) | Real hostname or IP |
User | $USER | Remote login name |
Port | 22 | Remote port |
IdentityFile | ~/.ssh/id_* | Private key to offer |
IdentitiesOnly | no | Only use listed identity files (don't try agent keys) |
ProxyJump | — | Comma-separated jump hosts |
ProxyCommand | — | Arbitrary command to open the transport |
ServerAliveInterval | 0 | Keepalive interval in seconds |
ServerAliveCountMax | 3 | Max unanswered keepalives before disconnect |
ForwardAgent | no | Forward local agent to remote |
ForwardX11 | no | Forward X11 display |
StrictHostKeyChecking | ask | yes/no/ask/accept-new |
UserKnownHostsFile | ~/.ssh/known_hosts | Where to store/check host keys |
LogLevel | INFO | QUIET / INFO / VERBOSE / DEBUG |
Compression | no | Enable zlib compression |
ControlMaster | no | auto to enable multiplexing |
ControlPath | — | Socket path for mux (~/.ssh/cm-%r@%h:%p) |
ControlPersist | no | Keep master open (10m, yes) |
AddKeysToAgent | no | Auto-add key to ssh-agent on use |
BatchMode | no | Fail instead of prompting (scripts) |
ConnectTimeout | (OS) | Seconds before giving up |
Jump Host Example
Host bastion
HostName bastion.example.com
User ubuntu
IdentityFile ~/.ssh/bastion_key
Host db
HostName 10.0.1.50
User postgres
ProxyJump bastion
IdentityFile ~/.ssh/db_key
Host *.internal
ProxyJump bastion
User ubuntuNow ssh db automatically tunnels through bastion.
Multiplexing (Reuse Connections)
Host *
ControlMaster auto
ControlPath ~/.ssh/cm-%r@%h:%p
ControlPersist 10mAfter the first connection, subsequent ssh/scp/rsync to the same host reuse the socket.
Separate Known Hosts Per Host
Host staging
HostName staging.example.com
UserKnownHostsFile ~/.ssh/known_hosts_staging
StrictHostKeyChecking accept-newCI / Scripting Boilerplate
Host deploy-*
StrictHostKeyChecking accept-new
BatchMode yes
ConnectTimeout 10
IdentitiesOnly yes
IdentityFile ~/.ssh/ci_deployToken Substitutions in Config Values
| Token | Expands to |
|---|---|
%h | Remote hostname |
%p | Remote port |
%r | Remote username |
%n | Original hostname (before alias) |
%u | Local username |
%d | Local home directory |
%i | Local user ID |
ControlPath ~/.ssh/cm-%r@%h:%p # typical use of tokens