SSH Cheatsheet

Keys

Use this SSH reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.

Key Types at a Glance

AlgorithmFlagRecommended?Notes
Ed25519ed25519Yes — default choiceFast, small keys, strong security
ECDSAecdsaAcceptableCurve P-256/384/521
RSArsaOnly if neededUse ≥4096 bits; legacy compat
DSAdsaNoBroken, removed in OpenSSH 9+

Generate a Key Pair

# Ed25519 (recommended)
ssh-keygen -t ed25519 -C "pablo@example.com"

# Ed25519 with custom path
ssh-keygen -t ed25519 -f ~/.ssh/github_ed25519 -C "github key"

# RSA 4096 (legacy compat)
ssh-keygen -t rsa -b 4096 -C "pablo@example.com"

# No passphrase (automation / CI — be careful)
ssh-keygen -t ed25519 -N "" -f ~/.ssh/deploy_key

-C sets the comment field in the public key (cosmetic). -N "" sets an empty passphrase.

Key Files

~/.ssh/id_ed25519        # private key  — NEVER share
~/.ssh/id_ed25519.pub    # public key   — share freely

The public key is one line:

ssh-ed25519 AAAA...base64... pablo@example.com

Inspect Keys

# Show fingerprint of a public key
ssh-keygen -lf ~/.ssh/id_ed25519.pub

# Show fingerprint as randomart
ssh-keygen -lvf ~/.ssh/id_ed25519.pub

# Show the public key of a private key
ssh-keygen -yf ~/.ssh/id_ed25519

# Check what key type a file is
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub

Change or Remove Passphrase

ssh-keygen -p -f ~/.ssh/id_ed25519

Prompts for old passphrase, then new. Leave new empty to remove it.

Convert and Export

# Export public key in PEM format (for some cloud providers)
ssh-keygen -e -m pkcs8 -f ~/.ssh/id_ed25519.pub

# Convert OpenSSH private key → PEM (legacy)
ssh-keygen -p -m PEM -f ~/.ssh/id_rsa

Host Keys (Server Side)

Generated automatically by sshd on first start; stored in /etc/ssh/.

ls /etc/ssh/ssh_host_*          # list host key files
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub   # server fingerprint

Regenerate (e.g., after cloning a VM):

sudo rm /etc/ssh/ssh_host_*
sudo ssh-keygen -A              # regenerates all host key types
sudo systemctl restart sshd

Authorized Keys Format

Each line in ~/.ssh/authorized_keys is one allowed public key, with optional options prefix:

ssh-ed25519 AAAA...base64... comment
from="192.168.1.0/24" ssh-ed25519 AAAA...base64... restricted key
command="backup.sh",no-pty,no-x11-forwarding ssh-ed25519 AAAA...base64... deploy
OptionEffect
from="pattern"Restrict to source IP / hostname
command="cmd"Force this command on connect
no-ptyDisable pseudo-terminal allocation
no-port-forwardingBlock tunneling
environment="VAR=val"Set an env variable