⚡
usefultools.dev
ssh

Chuleta de SSH

NUEVO

Chuleta de SSH: conexión, creación de claves, ~/.ssh/config, reenvío de puertos, hosts de salto, scp y rsync, ssh-agent, known_hosts, refuerzo de sshd y errores habituales. Con búsqueda y copia.

Es texto estático: nada de lo que escribes en el filtro sale de tu navegador. Los comandos, las opciones y sus descripciones breves se muestran en inglés.

78 entradas en 11 secciones

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.

⚡

Ejemplos rápidos

Entradas típicas y los resultados que produce esta herramienta.

Claves
Crear una clave Ed25519 nueva
ssh-keygen -t ed25519 -C "[email protected]"
Salto
Llegar a un host privado a través de un bastión
ssh -J bastion.example.com [email protected]
Túnel
Abrir el puerto local 8080 hacia el puerto 80 del servidor
ssh -L 8080:localhost:80 user@host
known_hosts
Eliminar una clave de host antigua tras reconstruir el servidor
ssh-keygen -R host
📖

Descripción general

SSH (Secure Shell) es la forma habitual de iniciar sesión en servidores, copiar archivos y enviar tráfico por una red que no es de confianza. Esta chuleta de SSH reúne los comandos que más se usan: conectarse con un puerto o una clave, generar e instalar claves, escribir un archivo ~/.ssh/config, reenviar puertos y pasar por un host de salto.

También incluye scp, rsync y sftp, ssh-agent, la gestión de known_hosts, la depuración con -v, las opciones de sshd_config que refuerzan un servidor y el significado de errores comunes como "Permission denied (publickey)". Los comandos, las opciones y las descripciones breves se muestran en inglés; en español están la interfaz y esta explicación. Filtra la lista y copia cualquier comando con un clic. La página es texto plano, carga rápido y nada de lo que escribes sale de tu navegador.

¿Por qué usar esta herramienta?

  • Encuentra la opción correcta sin leer todo el manual
  • Ejemplos de túneles, hosts de salto y configuración listos para adaptar
  • Explica los errores habituales de SSH y cómo resolverlos
  • Filtra por palabra clave, como key, tunnel o rsync
  • Copia un comando y sustituye user y host
⭐

Funciones

🔍

Filtro en vivo

Escribe una palabra clave para ver solo los comandos y secciones que coinciden.

📋

Copiar cada comando

Cada fila tiene un botón de copiar, y los bloques de configuración conservan sus saltos de línea.

🔑

Gestión de claves

Genera, instala, protege e inspecciona claves SSH.

🚇

Túneles y hosts de salto

Reenvíos locales, remotos y SOCKS, además de ejemplos con ProxyJump.

🛠️

Errores explicados

Mensajes habituales con su causa más frecuente y la solución.

📱

Apta para móvil

Los comandos largos se ajustan al ancho, así que las filas se leen bien en el teléfono.

🛠️

Cómo se usa

1

Elige una sección

Desplázate hasta Keys, Port forwarding, Copying files u otro grupo. Los títulos de las secciones están en inglés.

2

O usa el filtro

Escribe una palabra como "tunnel" o "permission" en el cuadro "Filtrar esta chuleta".

3

Lee la descripción

Cada comando indica qué hace y sus salvedades, por ejemplo que scp usa -P y ssh usa -p.

4

Copia y adapta

Pulsa Copiar, pega en tu terminal y sustituye marcadores como user, host y las rutas de las claves.

🤔

Preguntas frecuentes