Unprotected or Shared SSH Private Keys
SSH private keys are readable by others, have no passphrase, or are shared between people or systems, so anyone with a copy can log in wherever the key is trusted.
| Severity | High |
| CVSS 3.1 | 7.8 CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H Open in the calculator |
| CVSS 4.0 | 8.5 CVSS:4.0/AV:L/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N Open in the calculator |
| CWE | CWE-522: Insufficiently Protected Credentials |
| OWASP Top 10 | A06:2025 Insecure Design |
| MITRE ATT&CK | T1552.004 Private Keys, T1021.004 SSH |
| Category | Information Disclosure |
Description
An SSH private key is a credential: whoever holds a usable copy can log in as the key's account to every system that lists the matching public key in an authorized_keys file, without a password, and their access looks like that of the legitimate user. Keys belonging to root, administrators, deployment systems or service accounts often give privileged access to many servers at once, which makes them a common route for moving across Linux and Unix estates.
The weakness covers keys that are not adequately protected or controlled. Keys may be stored without a passphrase, so that the file alone is enough to log in immediately; kept with permissions that let other users read them, or copied into backups, shared drives, source code repositories, container images or virtual machine templates; or shared, with one key pair used by several administrators, or copied to many hosts and service accounts so that one key opens many systems. A key with a weak passphrase can be cracked offline. Shared keys also prevent the organisation from attributing actions to individuals or revoking one person's access without affecting others, and because plain SSH keys do not expire, they often remain trusted long after the person or system that needed them has gone.
The weakness is identified during host reviews and after gaining access to a system, by searching for private key files, such as id_rsa, id_ecdsa and id_ed25519, PuTTY .ppk files, and files containing a BEGIN OPENSSH PRIVATE KEY or similar header, and checking their permissions; by testing whether a key found is encrypted, for example with ssh-keygen -y -f, which asks for a passphrase only when the key has one; and by comparing authorized_keys entries across hosts to find keys that are reused or belong to people who have left.
Remediation
Protect each private key, give every person and system its own, and control where keys are trusted:
- Restrict private key files to their owner (
chmod 600, in a~/.sshdirectory with mode700) and remove keys from shared locations, readable backups, repositories, images and templates. Treat any key found in such a place as compromised: remove its public key from everyauthorized_keysfile and issue a new key pair. - Protect interactive users' keys with a strong passphrase (
ssh-keygen -padds one to an existing key) and usessh-agentso that it is not typed for every connection. Better still, keep keys on hardware security keys, using theed25519-skorecdsa-skkey types, or on smart cards, so that the private key cannot be copied. - Give every administrator their own key and named account, and every automated process its own key, restricted in
authorized_keyswith options such asfrom=,command=andrestrict. - Keep an inventory of trusted keys, review
authorized_keysfiles regularly and remove the keys of leavers and retired systems. Consider an SSH certificate authority, which issues short-lived certificates instead of permanent keys and removes the need to distributeauthorized_keysfiles. - Where users should not add their own keys, set
AuthorizedKeysFileto a root-owned location.
Confirm the fix by repeating the search for private keys, checking that those found are protected, and checking that keys exposed earlier no longer grant access.
References
Add This Finding to Your Library
In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.
Free trialYour trial starts when your portal goes live, not when you sign up, so the time you spend setting up does not count. · No card required
Only need the reporting? Our reporting tool is free and open source, with the same library.