SSH Cheat Sheet: Keys, Config, ProxyJump and Port Forwarding
Checked against OpenSSH OpenSSH 10.6p2 on 28 November 2026. Each section links to the official docs it was checked against.
This sheet covers the OpenSSH client you use every day to reach servers, Git hosts and bastions. It follows the OpenBSD manual pages and the release notes up to OpenSSH 10.6p2 (5 Nov 2026). Our sandbox blocks the ssh binaries, so every row was checked against the man pages rather than run, and is marked that way.
When to use what
Make a new key with Ed25519 unless a server or policy forces something else. It is short, fast and the man page lists it among the defaults ssh tries. Give it a passphrase and let ssh-agent remember it, so you type it once per login instead of leaving the key bare on disk.
Put anything you type more than twice into ~/.ssh/config. A Host block with HostName, User, IdentityFile and IdentitiesOnly yes turns a long command into ssh prod, and git, scp, rsync and VS Code Remote all read the same file. Remember the rule that surprises people: for most options the first value ssh sees wins, so put specific hosts at the top and the Host * defaults at the bottom.
For reaching a private machine, use ProxyJump (or -J) rather than agent forwarding. Jumping keeps your keys on your laptop; -A lets anyone with root on the middle host use your agent while you are connected. For tunnels, -L brings a remote port to your machine, -R exposes a local port on the remote side, and -D gives you a SOCKS proxy. Our SSH tunnels post walks through each with diagrams, and the SSH keys and signing post covers using the same key to sign Git commits.
ssh-keygen -t ed25519 -C "you@laptop"Create an Ed25519 key pair in ~/.ssh/id_ed25519 with a comment to identify it
ssh-keygen -t ed25519 -f ~/.ssh/id_workCreate a second key under a different file name, for example for a work account
ssh-keygen -p -f ~/.ssh/id_ed25519Add or change the passphrase on an existing private key
ssh-keygen -lf ~/.ssh/id_ed25519.pubPrint the SHA256 fingerprint of a key to compare with what a server or GitHub shows
ssh-keygen -y -f ~/.ssh/id_ed25519Rebuild the public key from a private key when the .pub file is lost
eval "$(ssh-agent -s)"Start an agent in this shell and export SSH_AUTH_SOCK so ssh can find it
ssh-add ~/.ssh/id_ed25519Load a key into the agent, asking for its passphrase once
ssh-add -lList the fingerprints of keys the agent currently holds
ssh-add -t 1h ~/.ssh/id_workLoad a key that the agent forgets after one hour
ssh-add -DRemove every key from the agent, for example before lending your laptop
For each option the first value found wins, except IdentityFile and CertificateFile, which add up. ssh -G host prints the final settings for a host without connecting, which is the fastest way to debug a config.
Host prod
HostName 203.0.113.10
User deploy
Port 2222Define an alias so ssh prod connects as deploy on port 2222
IdentityFile ~/.ssh/id_work
IdentitiesOnly yesOffer only this key, not every key in the agent, which avoids 'Too many authentication failures'
AddKeysToAgent yesAdd a key to the running agent the first time you type its passphrase
Include config.d/*Read extra files from ~/.ssh/config.d in name order, handy for per-project hosts
ssh -G prodPrint the fully resolved config for a host after all Host and Match blocks, then exit
ssh -J bastion.example.com app01Reach app01 by hopping through a bastion host, with keys staying on your machine
ProxyJump bastionConfig form of -J; list several hops with commas, or set none to turn it off
ssh -N -L 5433:localhost:5432 dbMake the remote Postgres reachable on localhost:5433 without opening a shell
ssh -N -R 8080:localhost:3000 serverExpose your local port 3000 as port 8080 on the server
ssh -N -D 1080 serverRun a SOCKS proxy on localhost:1080 that sends traffic out through the server
ssh -vvv prodConnect with maximum debug output to see which keys and config lines are used
ssh-keygen -R server.example.comDelete a host's old key from known_hosts after the server was rebuilt
ssh-keygen -F server.example.comCheck whether known_hosts already has a key for a host
StrictHostKeyChecking accept-newTrust first-time hosts automatically but still refuse a host whose key changed
ssh-keyscan github.comFetch a server's public host keys, to compare against its published fingerprints
Since OpenSSH 9.0, scp uses the SFTP protocol under the hood by default; -O switches back to the legacy protocol for old servers.
scp app.tar.gz prod:/tmp/Copy a local file to /tmp on a host from your config
scp -r prod:/var/log/app ./logsCopy a remote directory and its contents to your machine
scp -J bastion file.txt app01:Copy through a jump host into the remote user's home directory
sftp prodOpen an interactive session with ls, get, put and cd on the remote host
ssh ignores a private key that other users can read, and refuses a config file that others can write. The chmod calculator translates between these numbers and rwx letters.
chmod 700 ~/.sshLet only you list or enter the .ssh directory
chmod 600 ~/.ssh/id_ed25519Make a private key readable and writable by you only
chmod 600 ~/.ssh/config ~/.ssh/authorized_keysLock down the config and authorized_keys files to your user
chmod 644 ~/.ssh/id_ed25519.pubPublic keys can be world-readable; this is the usual mode
Worked example: Reach a private database through a bastion with one short command
You have a bastion at bastion.example.com and a Postgres server at 10.0.2.15 that only the bastion can reach. Add two entries to ~/.ssh/config:
Host bastion
HostName bastion.example.com
User you
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
Host db
HostName 10.0.2.15
User you
ProxyJump bastion
LocalForward 5433 localhost:5432
Then check what ssh will really do, and open the tunnel:
ssh -G db | grep -Ei '^(hostname|user|port|identityfile|proxyjump)'
ssh -N db
psql -h localhost -p 5433 -U app
According to the ssh man page, -G prints the settings ssh ends up with after it has read every Host and Match block, and it does this without connecting. Check five keys in that output. hostname should be the real address, which proves the alias matched. user and port show who you log in as and where, so you can spot a Host * default that overrode them. identityfile lists the keys ssh will try, in order. proxyjump should name the bastion, which proves the jump will happen. ssh -N db then logs in to the bastion, opens a second encrypted connection from there to the database host, and holds the forward open without starting a shell. While it runs, localhost:5433 on your laptop is the remote Postgres. Press Ctrl+C to close it.
Common mistakes
Getting 'UNPROTECTED PRIVATE KEY FILE' and a password prompt instead of key login.
The key is readable by others, so ssh skips it. Run
chmod 600on the private key andchmod 700on~/.ssh.Seeing 'Too many authentication failures' because the agent offers five keys before the right one.
Set
IdentityFilefor that host and addIdentitiesOnly yesso only that key is tried.Putting
Host *with a defaultUserat the top of the config and wondering why host-specific users are ignored.The first value wins. Move the catch-all
Host *block to the end of the file and confirm withssh -G.Turning on
StrictHostKeyChecking noto silence the 'host identification has changed' warning.Find out why the key changed. If the server was rebuilt, remove the old entry with
ssh-keygen -R hostand accept the new key;accept-newis the safer default for automation.Using
ssh -Aon every connection to reach Git from a server.Use
ProxyJumpto reach inner hosts, and a deploy key or short-lived token on the server for Git, so your agent isn't exposed to the remote root user.
Related cheat sheets
Sources
- https://man.openbsd.org/ssh
- https://man.openbsd.org/ssh_config
- https://man.openbsd.org/ssh-keygen
- https://man.openbsd.org/ssh-add
- https://man.openbsd.org/scp
- https://www.openssh.org/releasenotes.html
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.