SSH - only key
Ziel: Auf dem Client ein Ed25519-Schlüsselpaar mit Passphrase erzeugen und in ~/.ssh/config
hinterlegen. Auf dem Server Logins für root
und jj
auf Public-Key-Authentifizierung beschränken.
Platzhalter
SERVER_IP
: IP oder FQDN des Zielservers$Dieser_Client
: Kommentar (z. B. Hostname des Clients)little-ghost
: frei wählbarer Schlüsselnamens-Ordner
1) Client: SSH-Key mit Passphrase erzeugen
Befehl (kopierbar)
ssh-keygen \
-t ed25519 \
-a 2048 \
-o \
-Z aes256-ctr \
-C "$Dieser_Client" \
-f "/root/.ssh/JSc/little-ghost/id_ed25519"
Beispielausgabe
Generating public/private ed25519 key pair.
Enter passphrase for "/root/.ssh/JSc/little-ghost/id_ed25519" (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/JSc/little-ghost/id_ed25519
Your public key has been saved in /root/.ssh/JSc/little-ghost/id_ed25519.pub
The key fingerprint is:
SHA256:**************************** little-ghost
The key's randomart image is:
+--[ED25519 256]--+
|*****************|
|*****************|
|*****************|
|*****************|
|*****************|
|*****************|
|*****************|
|*****************|
|*****************|
+----[SHA256]-----+
Optional: Rechte setzen
chmod 700 /root/.ssh /root/.ssh/JSc /root/.ssh/JSc/little-ghost
chmod 600 /root/.ssh/JSc/little-ghost/id_ed25519
chmod 644 /root/.ssh/JSc/little-ghost/id_ed25519.pub
Beispielausgabe
# (keine Ausgabe bei Erfolg)
# Kontrolle:
ls -ld /root/.ssh /root/.ssh/JSc /root/.ssh/JSc/little-ghost
ls -l /root/.ssh/JSc/little-ghost/
2) Client: SSH-Konfiguration für Zielhost
In /root/.ssh/config
eintragen/ergänzen:
Dateiinhalt (kopierbar)
Host SERVER_IP
HostName SERVER_IP
IdentitiesOnly yes
IdentityFile /root/.ssh/JSc/little-ghost/id_ed25519
ForwardAgent no
ForwardX11 no
StrictHostKeyChecking ask
UserKnownHostsFile /root/.ssh/known_hosts
Beispielausgabe
# Kontrolle:
cat /root/.ssh/config
3) Client: Public Key anzeigen/kopieren
Befehl (kopierbar)
cat /root/.ssh/JSc/little-ghost/id_ed25519.pub
Beispielausgabe
ssh-ed25519 AAAAAAAAAABBBBBBBBBB/CCCCCCCCCC little-ghost
Diesen Einzeiler auf dem Server in die Datei ~<user>/.ssh/authorized_keys
einfügen (eine Zeile pro Key, keine Umbrüche).
4) Server: root
nur per Public Key
Datei /etc/ssh/sshd_config.d/10-root-only-key.conf
anlegen/ändern.
Dateiinhalt (kopierbar)
# Root: nur noch Public-Key, keine Passwörter/Keyboard-Interactive
Match User root
PubkeyAuthentication yes
PasswordAuthentication no
KbdInteractiveAuthentication no
AuthenticationMethods publickey
PermitRootLogin prohibit-password
Beispielausgabe
# Kontrolle:
cat /etc/ssh/sshd_config.d/10-root-only-key.conf
5) Server: jj
nur per Public Key
Datei /etc/ssh/sshd_config.d/20-jj-only-key.conf
anlegen/ändern.
Dateiinhalt (kopierbar)
# jj: nur noch Public-Key, keine Passwort-/Keyboard-Interactive-Logins
Match User jj
PubkeyAuthentication yes
PasswordAuthentication no
KbdInteractiveAuthentication no
AuthenticationMethods publickey
Beispielausgabe
# Kontrolle:
cat /etc/ssh/sshd_config.d/20-jj-only-key.conf
6) Server: Syntax prüfen & Dienst neu laden
Befehl (kopierbar)
sshd -t
sleep 30
systemctl reload ssh # Debian-Standarddienstname
Beispielausgabe
# Bei korrekter Konfiguration keine Ausgabe.
# Fehler würden hier mit Zeile/Datei gemeldet werden.
7) Client: Login zum Server testen
Befehl (kopierbar)
ssh SERVER_IP
Beispielausgabe
The authenticity of host 'SERVER_IP (SERVER_IP)' can't be established.
ED25519 key fingerprint is SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'SERVER_IP' (ED25519) to the list of known hosts.
Enter passphrase for key '/root/.ssh/JSc/little-ghost/id_ed25519':
Last login: Wed Sep 24 12:34:56 2025 from 203.0.113.42
root@server:~#
Hinweise
- Dateirechte: Verzeichnisse
700
, Private Key600
, Public Key644
. - Known Hosts: Datei heißt
known_hosts
(nichtknown_hos
). - Debug bei Problemen:
ssh -v SERVER_IP
zeigt, welchen Key der Client nutzt.
Stand: 25.09.2025
No Comments