Skip to main content
Key-only SSH restricts how users authenticate. It does not limit which accounts exist. A machine dedicated to hosting should have one account per administrator and no others.

Find every account that can log in

ubuntu from a cloud image and oldadmin from the machine’s previous configuration are the accounts to look for.

Check for accounts with no password set

No output is the correct result.

See who can become root

Then check for accounts that can sudo without a password prompt:
A NOPASSWD line is not necessarily wrong, because some monitoring agents require one. Each line should be scoped to specific commands and should be one you added deliberately.

Remove accounts that are no longer needed

Lock an account before deleting it. Locking is reversible and confirms whether anything on the machine depended on the account:
Never run this against your own account. Your current session and sudo keep working, so the effect is not visible until your next login attempt.
Unlocking requires both flags. usermod -U unlocks the password but leaves the expiry date, and the account still refuses logins with Your account has expired:
Before deleting an account, check what it owns and whether it is running anything. -xdev keeps find on the root filesystem rather than descending into container storage and network mounts, which on a host machine can take a long time and compete with client I/O:
Container filesystems store raw numeric UIDs, so files created inside an instance can appear to belong to a host account with the same UID. Files under Docker’s storage directory are not evidence that a host account is in use.Deleting an account frees its UID, and the next account created can inherit ownership of those files.
Once nothing depends on the account, remove it with its home directory and keys: