⚡
usefultools.dev
ssh

SSH-Spickzettel

NEU

SSH-Spickzettel: Verbinden, Schlüssel erstellen, ~/.ssh/config, Portweiterleitung, Jump-Hosts, scp und rsync, ssh-agent, known_hosts, sshd-Härtung und häufige Fehler. Mit Suche und Kopieren.

Die Seite besteht aus statischem Text: Was du in den Filter tippst, verlässt deinen Browser nicht. Befehle, Optionen und ihre Kurzbeschreibungen werden auf Englisch angezeigt.

78 Einträge in 11 Abschnitten

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.

⚡

Schnelle Beispiele

Typische Eingaben und die Ergebnisse, die dieses Tool liefert.

Schlüssel
Einen neuen Ed25519-Schlüssel erstellen
ssh-keygen -t ed25519 -C "[email protected]"
Sprung
Einen privaten Host über einen Bastion-Host erreichen
ssh -J bastion.example.com [email protected]
Tunnel
Lokalen Port 8080 auf Port 80 des Servers leiten
ssh -L 8080:localhost:80 user@host
known_hosts
Einen alten Host-Schlüssel nach einer Neuinstallation entfernen
ssh-keygen -R host
📖

Überblick

SSH (Secure Shell) ist der übliche Weg, sich auf Servern anzumelden, Dateien zu kopieren und Datenverkehr durch ein nicht vertrauenswürdiges Netzwerk zu tunneln. Dieser SSH-Spickzettel bündelt die Befehle, die du am häufigsten brauchst: Verbinden mit Port oder Schlüssel, Schlüssel erzeugen und installieren, eine ~/.ssh/config schreiben, Ports weiterleiten und über einen Jump-Host springen.

Außerdem enthält er scp, rsync und sftp, ssh-agent, die Verwaltung von known_hosts, das Debugging mit -v, die sshd_config-Optionen, die einen Server härten, und die Bedeutung häufiger Fehler wie „Permission denied (publickey)“. Befehle, Optionen und Kurzbeschreibungen bleiben auf Englisch; Oberfläche und diese Erklärung sind auf Deutsch. Filtere die Liste und kopiere jeden Befehl mit einem Klick. Die Seite ist reiner Text, lädt schnell, und nichts, was du eingibst, verlässt deinen Browser.

Warum dieses Tool?

  • Die passende Option finden, ohne die ganze Man-Page zu lesen
  • Beispiele für Tunnel, Jump-Hosts und Konfiguration zum Anpassen
  • Erklärt häufige SSH-Fehler und wie du sie behebst
  • Nach Stichwort filtern, zum Beispiel key, tunnel oder rsync
  • Befehl kopieren und user sowie host ersetzen
⭐

Funktionen

🔍

Live-Filter

Gib ein Stichwort ein, um nur die passenden Befehle und Abschnitte zu sehen.

📋

Kopieren pro Befehl

Jede Zeile hat eine Kopieren-Schaltfläche, und Konfigurationsblöcke behalten ihre Zeilenumbrüche.

🔑

Schlüsselverwaltung

SSH-Schlüssel erzeugen, installieren, schützen und prüfen.

🚇

Tunnel und Jump-Hosts

Lokale, Remote- und SOCKS-Weiterleitungen sowie ProxyJump-Beispiele.

🛠️

Fehler erklärt

Häufige Meldungen mit der üblichen Ursache und der Lösung.

📱

Mobilfreundlich

Lange Befehle werden umgebrochen, damit die Zeilen auch auf dem Smartphone lesbar bleiben.

🛠️

So funktioniert’s

1

Abschnitt wählen

Scrolle zu Keys, Port forwarding, Copying files oder einer anderen Gruppe. Die Abschnittstitel sind auf Englisch.

2

Oder den Filter nutzen

Gib ein Wort wie „tunnel“ oder „permission“ in das Feld „Diesen Spickzettel filtern“ ein.

3

Beschreibung lesen

Jeder Befehl sagt, was er tut, und nennt Besonderheiten, etwa dass scp -P und ssh -p verwendet.

4

Kopieren und anpassen

Klicke auf Kopieren, füge den Befehl in dein Terminal ein und ersetze Platzhalter wie user, host und Schlüsselpfade.

🤔

Häufig gestellte Fragen