SSH Cheat Sheet
Connections, keys, tunnels, and agent forwarding — the standard safe entry point to every server.
Connecting
7ssh user@hostConnect as a user
ssh -i KEY.pem user@hostConnect with a specific key
ssh -p 2222 user@hostNon-standard port
ssh user@host 'command'Run a command and exit
ssh -o StrictHostKeyChecking=no user@hostSkip host-key prompt (test only)
ssh -vvv user@hostDebug connection verbosely
ssh -v user@host exitShorter verbose trace
Keys & Agent
8ssh-keygen -t ed25519 -C 'you@example.com'Modern key generation
ssh-keygen -t rsa -b 4096RSA fallback for old systems
ssh-copy-id user@hostInstall your public key
cat ~/.ssh/id_ed25519.pubPrint the public key
ssh-add ~/.ssh/id_ed25519Add a key to the agent
ssh-add -lKeys currently in the agent
ssh-keygen -pChange a key passphrase
ssh-keygen -lf KEY.pubFingerprint for verification
Tunnels & Forwarding
7ssh -L 8080:internal:80 user@hostLocal forward (browse internal sites)
ssh -R 9000:localhost:3000 user@hostRemote forward (expose local)
ssh -D 1080 user@hostDynamic SOCKS proxy
ssh -L 5432:db.internal:5432 tunnel@hostTunnel into a database
ssh -A user@hostForward the SSH agent
ssh -N -L 8080:internal:80 user@hostNo shell, just the tunnel
ssh -o ProxyJump=bastion user@targetJump through a bastion
~/.ssh/config
5Host prod
HostName 1.2.3.4
User deploy
IdentityFile ~/.ssh/prodNamed host shortcut with key
Host *.internal
ProxyJump bastionRoute a group through a jump host
Host *
ServerAliveInterval 60Keep dead links from hanging
Host *
AddKeysToAgent yes
UseKeychain yesConvenience for macOS
Host github.com
HostName ssh.github.com
Port 443GitHub over port 443 (restricted net)
Hardening
6PermitRootLogin noDisable root logins
PasswordAuthentication noKeys only
Port 2222Move off default 22
MaxAuthTries 3Limit auth attempts
AllowUsers alice bobOnly listed users may log in
sshd -tValidate sshd config