SSH Cheatsheet
NOUVEAUSSH cheatsheet: connect, create keys, ~/.ssh/config, port forwarding, jump hosts, scp and rsync, ssh-agent, known_hosts, sshd hardening and common errors. Searchable, with copy.
Fonctionne à 100 % dans votre navigateur — vos données ne sont jamais envoyées ni stockées sur nos serveurs.
Cet outil n'est pas encore entièrement traduit : une partie du texte est encore en anglais. L'outil lui-même fonctionne de la même façon dans toutes les langues.
78 entrées dans 11 sections
Connecting
ssh user@hostOpen a shell on a remote machine.
ssh -p 2222 user@hostConnect to a non-default port (the default is 22).
ssh -i ~/.ssh/id_ed25519 user@hostUse a specific private key.
ssh user@host 'uptime'Run one command on the remote side and return.
ssh -t user@host 'sudo systemctl status nginx'Force a terminal (-t) for commands that need one, such as sudo prompts or top.
ssh -o ConnectTimeout=5 user@hostSet any config option for this connection with -o; here a 5 second connect timeout.
~.Typed at the start of a line: kill a frozen SSH session (press Enter first, then ~ and .).
Keys
ssh-keygen -t ed25519 -C "[email protected]"Create a new Ed25519 key pair; the comment helps you recognise it later.
ssh-keygen -t rsa -b 4096Create a 4096-bit RSA key for servers that do not support Ed25519.
ssh-keygen -t ed25519 -f ~/.ssh/work_keyCreate the key under a chosen file name.
ssh-copy-id user@hostInstall your public key in the server's ~/.ssh/authorized_keys.
ssh-copy-id -i ~/.ssh/work_key.pub user@hostInstall a specific public key.
ssh-keygen -p -f ~/.ssh/id_ed25519Add or change the passphrase of a private key.
ssh-keygen -y -f ~/.ssh/id_ed25519Print the public key that belongs to a private key.
ssh-keygen -lf ~/.ssh/id_ed25519.pubShow the fingerprint of a key.
chmod 700 ~/.ssh && chmod 600 ~/.ssh/id_ed25519 ~/.ssh/authorized_keysSet the strict permissions SSH requires on the folder, the private key and authorized_keys.
Client config (~/.ssh/config)
A Host block turns a long command into a short alias: ssh prod.
Host prod HostName 203.0.113.10 User deploy Port 2222 IdentityFile ~/.ssh/prod_keyAlias with host, user, port and key; connect with ssh prod.
Host * ServerAliveInterval 60 ServerAliveCountMax 3Send a keep-alive every 60 seconds so idle connections are not dropped by NAT or firewalls.
Host internal HostName 10.0.0.5 User admin ProxyJump bastionReach a private host through the jump host defined as "bastion".
Host github.com User git IdentityFile ~/.ssh/github_key IdentitiesOnly yesUse one specific key for one site and offer no other keys.
Host * AddKeysToAgent yesAdd each key to the running agent the first time it is used.
Host * ControlMaster auto ControlPath ~/.ssh/cm-%r@%h:%p ControlPersist 10mReuse one connection for later sessions to the same host, so they open instantly.
ssh -G prodPrint the final configuration SSH would use for a host.
Port forwarding (tunnels)
ssh -L 8080:localhost:80 user@hostLocal forward: localhost:8080 on your machine reaches port 80 as seen from the server.
ssh -L 5432:db.internal:5432 user@bastionReach a database that only the bastion can see, through a local port.
ssh -R 9000:localhost:3000 user@hostRemote forward: port 9000 on the server reaches port 3000 on your machine.
ssh -D 1080 user@hostStart a local SOCKS5 proxy on port 1080 that sends traffic through the server.
ssh -fN -L 8080:localhost:80 user@hostKeep only the tunnel: -N runs no remote command, -f moves SSH to the background.
ssh -X user@hostForward X11 so remote graphical programs open on your screen (-Y is the trusted variant).
Jump hosts
ssh -J bastion.example.com [email protected]Connect to a private host by hopping through a bastion server.
ssh -J user1@hop1,user2@hop2 user@targetChain several jump hosts, separated by commas.
scp -J bastion.example.com file.txt [email protected]:/tmp/Copy a file through a jump host.
ssh -A user@hostForward your agent so the server can use your local keys; only use it with hosts you trust.
Copying files: scp, rsync, sftp
scp file.txt user@host:/remote/dir/Upload a file.
scp user@host:/remote/file.txt .Download a file to the current folder.
scp -r project/ user@host:/remote/dir/Copy a folder recursively.
scp -P 2222 file.txt user@host:/tmp/Use another port; scp takes a capital -P, unlike ssh.
rsync -avz ./site/ user@host:/var/www/site/Sync a folder: archive mode, verbose, compressed. A trailing slash on the source copies its contents.
rsync -avzn ./site/ user@host:/var/www/site/Dry run: show what would change without changing anything.
rsync -avz --delete ./site/ user@host:/var/www/site/Also delete files on the target that no longer exist in the source. Check with a dry run first.
rsync -avz -e "ssh -p 2222" ./site/ user@host:/var/www/site/Run rsync over SSH on a custom port.
sftp user@hostOpen an interactive file-transfer session.
put local.txt / get remote.txtInside sftp: upload / download a file (lcd, lls and lpwd work on your local side).
ssh-agent
eval "$(ssh-agent -s)"Start an agent in the current shell and set its environment variables.
ssh-add ~/.ssh/id_ed25519Load a key into the agent so you type its passphrase once.
ssh-add -lList the keys the agent holds.
ssh-add -t 3600 ~/.ssh/id_ed25519Load a key that the agent forgets after one hour.
ssh-add --apple-use-keychain ~/.ssh/id_ed25519On macOS, store the passphrase in the Keychain.
ssh-add -DRemove every key from the agent.
known_hosts
ssh-keygen -R hostRemove a host's old entry from ~/.ssh/known_hosts, for example after a server was rebuilt.
ssh-keygen -F hostCheck whether a host is in known_hosts.
ssh-keyscan -t ed25519 hostFetch a server's public host key; verify its fingerprint through another channel before trusting it.
ssh -o StrictHostKeyChecking=accept-new user@hostTrust a host the first time you see it, but still refuse if its key changes later.
Debugging
ssh -v user@hostVerbose output; -vv and -vvv add more detail about keys and negotiation.
ssh -T [email protected]Test key authentication against GitHub without opening a shell.
nc -zv host 22Check that the port is reachable at all (nc must be installed).
sudo sshd -tTest sshd_config for mistakes before reloading the server.
sudo sshd -TPrint the effective server configuration.
sudo journalctl -u ssh -fFollow the server log on systemd systems; the unit is called sshd on RHEL-family distributions.
sudo tail -f /var/log/auth.logServer log on Debian and Ubuntu (/var/log/secure on RHEL-family).
Server hardening (/etc/ssh/sshd_config)
Keep a second session open while you test changes, so a mistake does not lock you out. Reload with sudo systemctl reload ssh (sshd on RHEL-family).
PasswordAuthentication noAllow only key logins, which removes password guessing.
PubkeyAuthentication yesAllow public-key logins.
PermitRootLogin noForbid logging in directly as root; use sudo after a normal login.
KbdInteractiveAuthentication noDisable keyboard-interactive logins, which can be another way to type a password (older OpenSSH versions call it ChallengeResponseAuthentication).
AllowUsers deploy aliceOnly these accounts may log in.
MaxAuthTries 3Disconnect after three failed attempts per connection.
Port 2222Listen on another port. It cuts log noise but is not real security.
X11Forwarding noTurn off X11 forwarding if you do not use it.
Common errors
Permission denied (publickey).The server did not accept any key. Check the user name, that the public key is in authorized_keys, the key permissions, and run ssh -v.
WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!The host key differs from known_hosts. If the server was reinstalled, run ssh-keygen -R host; otherwise investigate before connecting.
Host key verification failed.The host key could not be verified or does not match known_hosts. Remove the old entry with ssh-keygen -R host and confirm the new key.
ssh: connect to host example.com port 22: Connection refusedNothing is listening on that port: sshd is not running, or the port is wrong.
ssh: connect to host example.com port 22: Connection timed outPackets are not arriving: wrong address, a firewall or security group blocking the port, or the host is down.
ssh: Could not resolve hostnameThe name does not resolve. Check the spelling, DNS and your Host alias.
WARNING: UNPROTECTED PRIVATE KEY FILE!The private key is readable by others. Fix with chmod 600 on the key file.
Bad owner or permissions on ~/.ssh/configConfig must be owned by you and not writable by others: chmod 600 ~/.ssh/config.
Too many authentication failuresThe agent offered too many keys. Use -i with a key and -o IdentitiesOnly=yes.
no matching host key type found. Their offer: ssh-rsaAn old server only offers ssh-rsa, which modern clients disable. Upgrade the server; as a temporary workaround use -o HostKeyAlgorithms=+ssh-rsa.
Exemples rapides
Des entrées typiques et les résultats produits par cet outil.
Présentation
SSH (Secure Shell) is how most people log in to servers, copy files and tunnel traffic over an untrusted network. This SSH cheatsheet gathers the commands you use most: connecting with a port or key, generating and installing keys, writing a ~/.ssh/config file, forwarding ports and hopping through a jump host.
It also covers scp, rsync and sftp, ssh-agent, known_hosts management, debugging with -v, the sshd_config options that harden a server, and what common errors such as "Permission denied (publickey)" mean. Filter the list and copy any command with one click. The page is plain text, so it loads quickly and nothing you type leaves your browser.
Pourquoi utiliser cet outil ?
- Find the right flag without reading the whole man page
- Tunnel, jump host and config examples ready to adapt
- Explains common SSH errors and how to fix them
- Filter by keyword such as key, tunnel or rsync
- Copy a command and replace user and host
Fonctionnalités
Live filter
Type a keyword to show only the matching commands and sections.
Copy per command
Each row has a Copy button, and config blocks keep their line breaks.
Key management
Generate, install, protect and inspect SSH keys.
Tunnels and jump hosts
Local, remote and SOCKS forwards plus ProxyJump examples.
Errors explained
Common messages with the usual cause and fix.
Mobile friendly
Long commands wrap, so rows stay readable on a phone.
Mode d'emploi
Pick a section
Scroll to Keys, Port forwarding, Copying files or another group.
Or use the filter
Type a word like "tunnel" or "permission" in the "Filter this cheatsheet" box.
Read the description
Each command says what it does and any caveat, such as scp using -P and ssh using -p.
Copy and adapt
Press Copy, paste into your terminal and replace placeholders like user, host and key paths.