Chuleta de SSH
NUEVOChuleta 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@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.
Ejemplos rápidos
Entradas típicas y los resultados que produce esta herramienta.
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
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.
O usa el filtro
Escribe una palabra como "tunnel" o "permission" en el cuadro "Filtrar esta chuleta".
Lee la descripción
Cada comando indica qué hace y sus salvedades, por ejemplo que scp usa -P y ssh usa -p.
Copia y adapta
Pulsa Copiar, pega en tu terminal y sustituye marcadores como user, host y las rutas de las claves.