SSH Cheatsheet

SSH command cheatsheet

Every SSH incantation from the Toolbox post, in one place — connect, authenticate with keys, copy files, tunnel, and lock the server down. Client commands run on your machine; the hardening block is server-side.

Connect

CommandWhat it does
ssh user@hostopen a shell on a remote machine
ssh -p 2222 user@hostconnect on a non-standard port
ssh web01connect using a ~/.ssh/config alias
ssh -v user@hostverbose — show why a connection is failing
exit / Ctrl-Dclose the session

Keys

CommandWhat it does
ssh-keygen -t ed25519 -C "you@laptop"make a new key pair
ssh-copy-id user@hostinstall your public key on a server
ssh-add ~/.ssh/id_ed25519load the key into the agent (passphrase once)
cat ~/.ssh/id_ed25519.pubshow your public key
chmod 600 ~/.ssh/id_ed25519fix “permissions too open” errors

Copy files

CommandWhat it does
scp file user@host:/path/copy a local file up
scp user@host:/path/file .copy a remote file down
scp -r dir user@host:/path/copy a directory (recursive)
sftp user@hostinteractive file transfer

Tunnels & jumps

CommandWhat it does
ssh -L 8080:localhost:80 hostforward remote :80 to your local :8080
ssh -D 1080 hosta quick SOCKS proxy through the host
ssh -J bastion hosthop through a jump host to a private box

Your ~/.ssh/config

Host web01
    HostName 203.0.113.10
    User mitch
    Port 22
    IdentityFile ~/.ssh/id_ed25519

Host db01
    HostName 10.0.0.5
    User mitch
    ProxyJump web01      # reach db01 by hopping through web01

Define it once, then just ssh web01 (tab-completion works on the names).

Server hardening (/etc/ssh/sshd_config)

DirectiveEffect
PasswordAuthentication nokeys only — no password guessing
PermitRootLogin nono direct root login (sudo up instead)
AllowUsers mitchonly listed users may connect
Port 2222move off the default (a speed bump, not a lock)
sudo systemctl restart sshapply changes (keep a session open to test!)

Warning

Before disabling password auth, confirm your key logs you in and keep your current session open while you test a second one. Lock yourself out of a remote box and the only way back may be a data-centre console ticket.

When it won’t behave

CommandWhat it does
ssh -v user@hostverbose output — the first debugging step
ssh-keygen -R hostforget a changed host key (after a genuine rebuild)
ssh-add -llist keys currently loaded in the agent

Pairs with the Toolbox post SSH and the Endless Connectivity.