When attackers add their own SSH keys, they can return to the environment without repeating the original intrusion path. That persistence lets them regain access after remediation, maintain command-line control, and expand to other systems through lateral movement. If defenders only remove known keys, the attacker may still retain a hidden foothold. Full discovery and review of all keys is therefore essential.
When an attacker can place their own ssh key in a compromised environment, the key becomes a durable login path that survives password resets, many account lockouts, and sometimes even a partial cleanup. The practical problem is not just initial compromise, but hidden persistence, because remote shell access can be re-established long after the original intrusion method is blocked.
That persistence is especially dangerous in environments where SSH is used for administration, automation, and inter-system trust. Once the attacker has command-line access, they can work quietly, collect more credentials, enumerate reachable hosts, and move laterally without needing to repeat the original exploit chain.
Defenders should treat unauthorized key insertion as an access-control failure, not simply as a one-off artifact to delete. A full response has to account for where the key was added, which accounts accept it, whether the same key appears elsewhere, and whether other trust paths were altered at the same time.
Why a Rogue SSH Key Creates Persistent Access
An SSH key works as an authentication factor, so adding an attacker-controlled public key gives the attacker a reusable proof of possession tied to the account. If that key is accepted by a privileged or service account, the attacker can return directly, often without triggering the same user-facing alerts that a password-based login might produce.
That durability matters because many remediation efforts focus on the obvious credential, such as a leaked password, while the planted key remains valid. In practice, the attacker does not need to stay present continuously; they only need the key accepted once the environment is quiet again.
For a broader treatment of how stolen or planted keys support ongoing compromise, see The 52 NHI Breaches Report, which includes real-world compromise patterns involving keys, credentials, and lateral movement.
How Attackers Use the Foothold After Re-entry
Once the attacker can authenticate again, the SSH session becomes a control channel. From there they can inspect configuration, harvest additional secrets, stage tools, and pivot to other systems that trust the same operator network, automation account, or shared administrative workflow.
The key risk is that SSH access is often broad enough to support both stealth and expansion. A single compromised key may open a path to multiple hosts, especially when administrators reuse accounts, copy authorized_keys content across systems, or rely on shared bastion patterns without strong separation.
That is why the attack pattern is usually more than simple login persistence. It can support command execution, repeated reconnaissance, and lateral movement, all while blending into normal administration traffic if logging and key ownership review are weak.
What Defenders Must Verify Before Declaring Cleanup Complete
Removing a known malicious key is necessary, but it is not sufficient. Teams need to verify the full authorized_keys inventory, check for duplicate or shadowed keys across accounts and hosts, review recent file and account changes, and confirm that no attacker-controlled automation path still authenticates through SSH.
The most common failure is assuming that one discovered key equals one attacker foothold. In real incidents, attackers often leave more than one path, or they establish access through multiple users, so cleanup has to be based on discovery and confirmation rather than a single-point removal.
What to verify: Treat every account with SSH access as part of the review scope, including service and break-glass accounts. Confirm who owns each key, when it was added, where it is accepted, and whether any key grants access that no longer matches an operational need.
What good looks like: Every authorized key is attributable, necessary, and reviewed; unexpected keys are removed; and access is revalidated after rotation so the attacker cannot simply return through an overlooked trust path.
Risk and Threat Considerations
Planted SSH keys create a durable re-entry mechanism that can outlast incident response if defenders focus on visible malware or the original intrusion vector. The security problem is compounded when the key lands on accounts with broad reach, because the attacker can regain access and continue staging, reconnaissance, or lateral movement with minimal friction.
Failure mechanism: The attacker adds a public key to an account that remains trusted by SSH, then waits for remediation to finish while the key continues to authenticate silently.
Impact: The environment retains a hidden foothold, making eradication incomplete and allowing renewed access, privilege abuse, and expansion to adjacent systems.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
MITRE ATT&CK addresses the attack and risk surface, while CIS Controls v8, NIST SP 800-53 Rev 5 and NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| MITRE ATT&CK | T1098 — Account Manipulation | SSH key insertion is account manipulation that preserves unauthorized access. |
| T1078 — Valid Accounts | A rogue SSH key lets attackers reuse legitimate authentication to regain access. | |
| Recommendation — Hunt for unauthorized account changes and remove attacker-added access paths. Treat unexpected SSH-key auth as valid-account abuse and review all trusted logins. | ||
| CIS Controls v8 | CIS-5 — Account Management | The issue hinges on controlling, reviewing, and removing unauthorized account access paths. |
| Recommendation — Review and revoke unauthorized SSH access in your account management process. | ||
| NIST SP 800-53 Rev 5 | IA-5 — Authenticator Management | SSH keys are authenticators whose lifecycle must be controlled to prevent persistent access. |
| AC-2 — Account Management | Unauthorized key insertion alters account access and requires account lifecycle control. | |
| SI-4 — System Monitoring | Detecting unauthorized key placement depends on monitoring account and configuration changes. | |
| Recommendation — Rotate, revoke, and inventory SSH authenticators tied to compromised access. Reconcile account access and remove unauthorized SSH-authorized principals. Monitor SSH key and account changes for signs of persistence or re-entry. | ||
| NIST Zero Trust (SP 800-207) | SC-7 — Boundary Protection | A hidden SSH key bypasses trust boundaries and enables lateral movement across systems. |
| Recommendation — Reduce lateral movement by segmenting SSH trust paths and restricting reachability. | ||
Practitioner Guidance
What to prioritise: Start with accounts that can reach the most systems, because a single high-value key can preserve far more access than a low-privilege compromise. If the attacker-controlled key sits on an administrative, automation, or shared service account, treat it as a containment issue before a routine cleanup issue.
Decision rule: If you cannot prove when a key was added and who approved it, assume it is part of the compromise until proven otherwise. Key removal should be paired with a fresh access review, because deleting the obvious key without validating the surrounding trust model leaves room for silent re-entry.
Practitioner takeaway: The real objective is not just to remove a malicious key, but to eliminate every place where that key could still authenticate, because persistence lives in the remaining trust path, not in the file you already found.
Related resources from NHI Mgmt Group
- What happens when attackers capture SSH credentials from a compromised workstation?
- What happens when developers are compromised and attackers obtain access tokens or private keys?
- What happens when attackers discover multiple compromised AWS access keys in the same environment?
- What happens when attackers combine C2 access, SSH brute force, and known host data on a compromised machine?
Deepen Your Knowledge
Reviewed and updated by the NHIMG editorial team on September 25, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org