Skip to content

Menu

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

Try it: ssh-key-generatorFrom the docs, not run by us
ssh-keygen -t ed25519 -f ~/.ssh/id_work

Create a second key under a different file name, for example for a work account

From the docs, not run by us
ssh-keygen -p -f ~/.ssh/id_ed25519

Add or change the passphrase on an existing private key

From the docs, not run by us
ssh-keygen -lf ~/.ssh/id_ed25519.pub

Print the SHA256 fingerprint of a key to compare with what a server or GitHub shows

From the docs, not run by us
ssh-keygen -y -f ~/.ssh/id_ed25519

Rebuild the public key from a private key when the .pub file is lost

From the docs, not run by us
eval "$(ssh-agent -s)"

Start an agent in this shell and export SSH_AUTH_SOCK so ssh can find it

From the docs, not run by us
ssh-add ~/.ssh/id_ed25519

Load a key into the agent, asking for its passphrase once

From the docs, not run by us
ssh-add -l

List the fingerprints of keys the agent currently holds

From the docs, not run by us
ssh-add -t 1h ~/.ssh/id_work

Load a key that the agent forgets after one hour

From the docs, not run by us
ssh-add -D

Remove every key from the agent, for example before lending your laptop

From the docs, not run by us

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 2222

Define an alias so ssh prod connects as deploy on port 2222

From the docs, not run by us
IdentityFile ~/.ssh/id_work IdentitiesOnly yes

Offer only this key, not every key in the agent, which avoids 'Too many authentication failures'

From the docs, not run by us
AddKeysToAgent yes

Add a key to the running agent the first time you type its passphrase

From the docs, not run by us
Include config.d/*

Read extra files from ~/.ssh/config.d in name order, handy for per-project hosts

From the docs, not run by us
ssh -G prod

Print the fully resolved config for a host after all Host and Match blocks, then exit

From the docs, not run by us
ssh -J bastion.example.com app01

Reach app01 by hopping through a bastion host, with keys staying on your machine

From the docs, not run by us
ProxyJump bastion

Config form of -J; list several hops with commas, or set none to turn it off

From the docs, not run by us
ssh -N -L 5433:localhost:5432 db

Make the remote Postgres reachable on localhost:5433 without opening a shell

From the docs, not run by us
ssh -N -R 8080:localhost:3000 server

Expose your local port 3000 as port 8080 on the server

From the docs, not run by us
ssh -N -D 1080 server

Run a SOCKS proxy on localhost:1080 that sends traffic out through the server

From the docs, not run by us
ssh -vvv prod

Connect with maximum debug output to see which keys and config lines are used

From the docs, not run by us
ssh-keygen -R server.example.com

Delete a host's old key from known_hosts after the server was rebuilt

From the docs, not run by us
ssh-keygen -F server.example.com

Check whether known_hosts already has a key for a host

From the docs, not run by us
StrictHostKeyChecking accept-new

Trust first-time hosts automatically but still refuse a host whose key changed

From the docs, not run by us
ssh-keyscan github.com

Fetch a server's public host keys, to compare against its published fingerprints

From the docs, not run by us

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

From the docs, not run by us
scp -r prod:/var/log/app ./logs

Copy a remote directory and its contents to your machine

From the docs, not run by us
scp -J bastion file.txt app01:

Copy through a jump host into the remote user's home directory

From the docs, not run by us
sftp prod

Open an interactive session with ls, get, put and cd on the remote host

From the docs, not run by us

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 ~/.ssh

Let only you list or enter the .ssh directory

chmod 600 ~/.ssh/id_ed25519

Make a private key readable and writable by you only

chmod 600 ~/.ssh/config ~/.ssh/authorized_keys

Lock down the config and authorized_keys files to your user

chmod 644 ~/.ssh/id_ed25519.pub

Public 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 600 on the private key and chmod 700 on ~/.ssh.

  • Seeing 'Too many authentication failures' because the agent offers five keys before the right one.

    Set IdentityFile for that host and add IdentitiesOnly yes so only that key is tried.

  • Putting Host * with a default User at 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 with ssh -G.

  • Turning on StrictHostKeyChecking no to 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 host and accept the new key; accept-new is the safer default for automation.

  • Using ssh -A on every connection to reach Git from a server.

    Use ProxyJump to 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.