What It Does
The script reads AuthorizedKeysFile paths reported by sshd -T. If no paths are reported it tries .ssh/authorized_keys and .ssh/authorized_keys2. It expands the path tokens for each account returned by getent with a home directory, including root. It prints one row per key: account, file, key type, size, SHA256 fingerprint, comment and any restrictions in front of the key, such as command=.
With ALLOWED_FINGERPRINTS set, each row says whether the key is on that list, and the answer counts the keys that are not. With no list it only reports. It never alerts: it ends OK unless it cannot run.
It does not cover keys handed out by AuthorizedKeysCommand (LDAP, FreeIPA, identity providers), SSH certificate authorities, or accounts whose home folder is not on this machine. A line it cannot read as a key is left out and counted in a warning.
Pair it with remove-ssh-authorized-key to remove a key by its fingerprint once you have decided it should go.
Before You Run It
- Run it as root. The script refuses to run without root privileges.
- Collect your approved fingerprints with ssh-keygen -l -E sha256 -f [keyfile] and pass them as ALLOWED_FINGERPRINTS.
- Check for keys it cannot see: LDAP or identity provider keys and certificate authorities are not covered.
- It was run on Ubuntu 24.04. Debian 12 and RHEL, Rocky and Alma 9 use the same files, but are written for rather than run.
Type and Risk
- Type: Report. It collects facts into a table and never alerts. It exits 0, or 2 when it could not run.
- Risk: Low. It reads and changes nothing.
- Restart: It never restarts the machine.
- Typical run: Under 10 seconds.
- Example answer: "7 key(s) in 3 file(s) for 3 account(s); 2 not on the allow list"
- Tested before listing on Ubuntu 24.04 (Arm64 VM) with bash, run as root, against its own test cases.
Inputs
Pass an input as an argument (--input-name value), as an environment variable named as listed, which is how most RMMs pass script variables, or change its default in the DEFAULT_ lines near the top of the script. An argument wins over an environment variable, which wins over the default.
- ALLOWED_FINGERPRINTS: SHA256 fingerprints that are approved (SHA256:abc...), comma-separated. Default none.
Every script also takes DRY_RUN, OUTPUT_FORMAT (Text, Answer, Json or Csv), EXPORT_PATH and RESULT_FIELD, which writes the answer to an RMM custom field, unless the list above words one differently.
License
Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.