SSH Cheatsheet
Keys, remote shells, port forwarding, config file.
1 credit
Keys
4 itemsGenerate ed25519 key
ssh-keygen -t ed25519 -C "you@host"Copy to server
ssh-copy-id user@hostTest agent
ssh-add -lAdd key to agent
ssh-add ~/.ssh/id_ed25519Connecting
5 itemsBasic
ssh user@hostSpecific key
ssh -i ~/.ssh/custom user@hostNon-default port
ssh -p 2222 user@hostRun remote command
ssh user@host "ls -la /var/log"Persistent connection
ssh -o ServerAliveInterval=60 user@hostPort forwarding
3 itemsLocal forward (localhost:5432 → remote DB)
ssh -L 5432:localhost:5432 user@hostRemote forward (expose local to server)
ssh -R 9000:localhost:3000 user@hostSOCKS proxy
ssh -D 1080 user@host~/.ssh/config
text
Host prod HostName 203.0.113.10 User deploy Port 2222 IdentityFile ~/.ssh/prod_ed25519 ForwardAgent yes Host * ServerAliveInterval 60 ControlMaster auto ControlPath ~/.ssh/cm-%r@%h:%p ControlPersist 10m
ControlMaster reuses a single TCP connection for multiple sessions — noticeably faster.
File transfer
3 itemsscp single file
scp local.txt user@host:/path/scp recursive
scp -r ./dir user@host:/path/rsync (better)
rsync -avz --progress ./dir user@host:/path/