ssh-hardening
SSH hardening
Establish working administrative access before restricting authentication. Keep the current session and provider console available until a fresh post-change login succeeds.
Inspect and establish access
-
Identify the active daemon/service/socket, actual listener ports, administrative and automation identities,
Includeorder, and relevantMatchrules. Recordsshd -T -Cresults for the actual users, client addresses, and hostnames. -
Use an existing non-root administrator. If account creation is needed, create it separately with the distribution's user/group conventions, install its public key, then prove key login and sudo in a separate session before any lockdown.
-
Generate personal keys on the local client with a passphrase or hardware-backed key. scripts/generate-ssh-keys.sh provides preview/no-overwrite behavior; its
--interactivemode is for a human terminal and--no-passphraseis an explicit service-key choice. -
Test the specific key without password fallback:
ssh -o IdentitiesOnly=yes -o PreferredAuthentications=publickey -i ~/.ssh/server_admin administrator@server.example.comIn that new session, verify the required sudo operation. Password fallback or an already-open session is not proof of usable key access.