AUTHORIZED_KEYS
SSH
OSQUERY
AUDITD
DetectionBlue TeamSOCOctober 12, 2026•9 min read

Detecting SSH authorized_keys Persistence on Linux

An added public key is the quietest back door on Linux. There is no new process, no new port and no password to rotate, only one extra line in a file.

Scroll

Appending an attacker’s public key to ~/.ssh/authorized_keys gives durable, password-less access that survives credential resets and looks like ordinary SSH. Cloud-focused and cryptomining campaigns do this routinely, and so do operators who want a fallback once the first foothold is lost. Detection combines file-change monitoring, inventory of authorised keys and logging of which key was used.

Signals at a Glance

SignalWhereATT&CK
Write or append to ~/.ssh/authorized_keys or authorized_keys2auditd, EDR file events, FIMT1098.004
New .ssh directory created in a service or system account homeauditd, osqueryT1098.004
Public key fingerprint in sshd logs not present in your key inventorysshd auth log (LogLevel VERBOSE)T1078
sshd_config changes: AuthorizedKeysFile, PermitRootLogin, PubkeyAuthenticationauditd on /etc/ssh/T1098.004
Key added by a non-interactive process (curl, bash -c, a web shell parent)EDR process + file correlationT1098.004
Login by key from a source address never seen for that accountauth log, VPN and flow dataT1021.004

Watching the Key Files

Start with write detection on the files that grant access. auditd cannot wildcard home directories, so generate per-user watches from your inventory or configuration tooling, and always include root and system accounts such as www-data, postgres and git:

# /etc/audit/rules.d/ssh-keys.rules
-w /root/.ssh/ -p wa -k ssh_keys
-w /etc/ssh/sshd_config -p wa -k sshd_config
-w /etc/ssh/sshd_config.d/ -p wa -k sshd_config
# Per-user watches: generate these for each account that has a home directory, for example
# -w /home/alice/.ssh/authorized_keys -p wa -k ssh_keys
# -w /var/lib/postgresql/.ssh/ -p wa -k ssh_keys
# Where kernel and EDR coverage allow, prefer a path regex over per-user rules:
#   TargetFilename matches /\.ssh/authorized_keys2?$ with a write or rename action
# tune/validate: legitimate writers are provisioning tools and cloud-init; filter on exe and auid.

Real-time rules miss keys planted before monitoring began. Inventory the keys on every host with osquery and compare them with the keys you expect. The query returns the owner, key comment and file modification time, so a key added since the last review stands out:

-- osquery: authorized keys per user, with file modification time
SELECT u.username,
       ak.key_file,
       ak.algorithm,
       ak.comment,
       substr(ak.key, 1, 24) AS key_prefix,
       datetime(f.mtime, 'unixepoch') AS file_mtime
FROM users u
JOIN authorized_keys ak USING (uid)
JOIN file f ON f.path = ak.key_file
ORDER BY f.mtime DESC;
-- tune/validate: key comments are attacker-controlled; compare key material or fingerprints, not comments.

Detecting Use of a Planted Key

Vetted sources

Use the SigmaHQ Linux file-event and SSH rules, Elastic’s SSH authorized-keys modification detections, Splunk ESCU content, MITRE CAR analytics and Atomic Red Team T1098.004 tests, along with the osquery authorized_keys table for inventory. Baseline your own environment, because provisioning tools and cloud-init legitimately write these files.

Build Detections That Fire

Mjolnir Security helps blue teams turn threat intelligence into high-fidelity detections across endpoint, network, identity and cloud telemetry.

Detection EngineeringManaged Detection & ResponseThreat HuntingIncident ResponsePurple Teaming
  • Detection Engineering We build and tune detections mapped to ATT&CK from your own telemetry.
  • Threat Hunting as a Service Hypothesis-driven hunts for the behaviours on this page.
  • 24/7 Incident Response Containment when a detection fires. Call +1 833 403 5875.
Written by: Mjolnir Threat Research (MTAC)  |  Published: October 12, 2026  |  Last reviewed: October 12, 2026