⚡
usefultools.dev
ssh

SSH Cheatsheet

NOUVEAU

SSH 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@host

    Open a shell on a remote machine.

  • ssh -p 2222 user@host

    Connect to a non-default port (the default is 22).

  • ssh -i ~/.ssh/id_ed25519 user@host

    Use 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@host

    Set 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 4096

    Create a 4096-bit RSA key for servers that do not support Ed25519.

  • ssh-keygen -t ed25519 -f ~/.ssh/work_key

    Create the key under a chosen file name.

  • ssh-copy-id user@host

    Install your public key in the server's ~/.ssh/authorized_keys.

  • ssh-copy-id -i ~/.ssh/work_key.pub user@host

    Install a specific public key.

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

    Add or change the passphrase of a private key.

  • ssh-keygen -y -f ~/.ssh/id_ed25519

    Print the public key that belongs to a private key.

  • ssh-keygen -lf ~/.ssh/id_ed25519.pub

    Show the fingerprint of a key.

  • chmod 700 ~/.ssh && chmod 600 ~/.ssh/id_ed25519 ~/.ssh/authorized_keys

    Set 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_key

    Alias with host, user, port and key; connect with ssh prod.

  • Host * ServerAliveInterval 60 ServerAliveCountMax 3

    Send 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 bastion

    Reach a private host through the jump host defined as "bastion".

  • Host github.com User git IdentityFile ~/.ssh/github_key IdentitiesOnly yes

    Use one specific key for one site and offer no other keys.

  • Host * AddKeysToAgent yes

    Add each key to the running agent the first time it is used.

  • Host * ControlMaster auto ControlPath ~/.ssh/cm-%r@%h:%p ControlPersist 10m

    Reuse one connection for later sessions to the same host, so they open instantly.

  • ssh -G prod

    Print the final configuration SSH would use for a host.

Port forwarding (tunnels)

  • ssh -L 8080:localhost:80 user@host

    Local forward: localhost:8080 on your machine reaches port 80 as seen from the server.

  • ssh -L 5432:db.internal:5432 user@bastion

    Reach a database that only the bastion can see, through a local port.

  • ssh -R 9000:localhost:3000 user@host

    Remote forward: port 9000 on the server reaches port 3000 on your machine.

  • ssh -D 1080 user@host

    Start a local SOCKS5 proxy on port 1080 that sends traffic through the server.

  • ssh -fN -L 8080:localhost:80 user@host

    Keep only the tunnel: -N runs no remote command, -f moves SSH to the background.

  • ssh -X user@host

    Forward 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@target

    Chain 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@host

    Forward 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@host

    Open an interactive file-transfer session.

  • put local.txt / get remote.txt

    Inside 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_ed25519

    Load a key into the agent so you type its passphrase once.

  • ssh-add -l

    List the keys the agent holds.

  • ssh-add -t 3600 ~/.ssh/id_ed25519

    Load a key that the agent forgets after one hour.

  • ssh-add --apple-use-keychain ~/.ssh/id_ed25519

    On macOS, store the passphrase in the Keychain.

  • ssh-add -D

    Remove every key from the agent.

known_hosts

  • ssh-keygen -R host

    Remove a host's old entry from ~/.ssh/known_hosts, for example after a server was rebuilt.

  • ssh-keygen -F host

    Check whether a host is in known_hosts.

  • ssh-keyscan -t ed25519 host

    Fetch a server's public host key; verify its fingerprint through another channel before trusting it.

  • ssh -o StrictHostKeyChecking=accept-new user@host

    Trust a host the first time you see it, but still refuse if its key changes later.

Debugging

  • ssh -v user@host

    Verbose 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 22

    Check that the port is reachable at all (nc must be installed).

  • sudo sshd -t

    Test sshd_config for mistakes before reloading the server.

  • sudo sshd -T

    Print the effective server configuration.

  • sudo journalctl -u ssh -f

    Follow the server log on systemd systems; the unit is called sshd on RHEL-family distributions.

  • sudo tail -f /var/log/auth.log

    Server 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 no

    Allow only key logins, which removes password guessing.

  • PubkeyAuthentication yes

    Allow public-key logins.

  • PermitRootLogin no

    Forbid logging in directly as root; use sudo after a normal login.

  • KbdInteractiveAuthentication no

    Disable keyboard-interactive logins, which can be another way to type a password (older OpenSSH versions call it ChallengeResponseAuthentication).

  • AllowUsers deploy alice

    Only these accounts may log in.

  • MaxAuthTries 3

    Disconnect after three failed attempts per connection.

  • Port 2222

    Listen on another port. It cuts log noise but is not real security.

  • X11Forwarding no

    Turn 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 refused

    Nothing is listening on that port: sshd is not running, or the port is wrong.

  • ssh: connect to host example.com port 22: Connection timed out

    Packets are not arriving: wrong address, a firewall or security group blocking the port, or the host is down.

  • ssh: Could not resolve hostname

    The 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/config

    Config must be owned by you and not writable by others: chmod 600 ~/.ssh/config.

  • Too many authentication failures

    The agent offered too many keys. Use -i with a key and -o IdentitiesOnly=yes.

  • no matching host key type found. Their offer: ssh-rsa

    An 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.

Keys
Create a new Ed25519 key
ssh-keygen -t ed25519 -C "[email protected]"
Jump
Reach a private host through a bastion
ssh -J bastion.example.com [email protected]
Tunnel
Open local port 8080 to the server's port 80
ssh -L 8080:localhost:80 user@host
known_hosts
Remove an old host key after a rebuild
ssh-keygen -R host
📖

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

1

Pick a section

Scroll to Keys, Port forwarding, Copying files or another group.

2

Or use the filter

Type a word like "tunnel" or "permission" in the "Filter this cheatsheet" box.

3

Read the description

Each command says what it does and any caveat, such as scp using -P and ssh using -p.

4

Copy and adapt

Press Copy, paste into your terminal and replace placeholders like user, host and key paths.

🤔

Questions fréquentes