Audit SSH authorized_keys & Remove Backdoors on Linux
Rotating passwords is not enough if an unknown key sits in ~/.ssh/authorized_keys. Learn how to fingerprint keys, strip rogue lines, verify counts, and check sshd logs on Australian Linux servers.
This guide is for Australian homeowners, small-business owners, and sysadmins who manage Ubuntu or other Linux VPS and dedicated servers over SSH. By the end you will list every key fingerprint in authorized_keys, remove unrecognised entries, confirm what remains, and review sshd logs for unauthorised access—without relying on password rotation alone.
Rotating passwords and patching the OS will not stop an attacker who planted a single unknown public key in ~/.ssh/authorized_keys. That key grants silent, passwordless login until you audit and clean the file. Fixwebnode provides remote Linux server support across Australia for this exact work when you need a specialist to finish the cleanup safely.
Why SSH authorized_keys audits matter on Linux servers
SSH public-key authentication is the standard way to log into production Linux boxes. Each line in a user’s ~/.ssh/authorized_keys is a standing invitation. Compromised deploy scripts, shared contractor access, or a past breach can leave keys you never intended. Attackers favour this persistence because it survives password changes, many package updates, and even some “reinstall the app” recoveries.
On servers used by Australian small businesses—web hosts, billing panels, file shares—a forgotten key is a quiet backdoor. The practical response is fingerprint every key, delete what you do not recognise, lock file permissions, and correlate recent logins in the sshd logs.
How do I remove a persistent SSH key backdoor on a Linux server in Australia?
List fingerprints with ssh-keygen -lf ~/.ssh/authorized_keys, delete unrecognised lines (for example with sed), confirm the remaining line count with wc -l, then inspect sshd auth logs for unexpected successful logins. If keys reappear after cleanup or you lack a known-good inventory, book remote Linux support so the full account and host hardening can be checked.
| Symptom | Quick fix | When to call Fixwebnode |
|---|---|---|
| Unknown fingerprint in authorized_keys | Remove that line; re-check with ssh-keygen -lf | Keys return after reboot or you cannot identify owners |
| More key lines than staff/deploy bots | sed out strangers; wc -l to verify | Multiple users/root copies; no baseline inventory |
| Successful logins you did not make | Match log fingerprints/IPs; rotate remaining keys | Ongoing access, altered sshd_config, or other backdoors |
Common issues when auditing authorized_keys
These problems show up repeatedly on small Linux fleets. Each has a different root cause and its own fix path.
- Unknown public keys still granting login — Fingerprints you cannot match to laptops, CI, or vendors; often left by former staff or malware.
- authorized_keys quietly rewritten after cleanup — A cron job, configuration-management agent, or second backdoor restores the rogue line.
- sshd shows successful key logins you never approved — Auth logs list Accepted publickey from unfamiliar IPs or users while the box still “feels” normal.
- Wrong permissions or duplicate key files — World-readable
.ssh, keys under/rootand deploy users, orAuthorizedKeysFilepointing somewhere you never checked.
Issue 1 — Unknown public keys still granting login
Symptom: ssh-keygen -lf prints fingerprints or comments you do not recognise, or the file has more lines than people and automation you trust.
Step 1 — Back up the file before editing
sudo cp -a ~/.ssh/authorized_keys ~/.ssh/authorized_keys.bak.$(date +%Y%m%d%H%M%S)
sudo cp -a /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bak.$(date +%Y%m%d%H%M%S) 2>/dev/null || true
Keep a timestamped copy so you can restore a mistaken deletion from the console or provider panel if you lock yourself out.
Step 2 — List every fingerprint and comment
ssh-keygen -lf ~/.ssh/authorized_keys
# If root may be compromised too:
sudo ssh-keygen -lf /root/.ssh/authorized_keys
Each line shows bit length, hash (SHA256 by default on modern OpenSSH), and optional comment. Compare comments and hashes to your password manager or inventory spreadsheet.
Step 3 — Show numbered lines so you can target removals
nl -ba ~/.ssh/authorized_keys
Step 4 — Remove an unrecognised line with sed
Replace N with the line number from nl. Example deletes line 3:
sed -i '3d' ~/.ssh/authorized_keys
To delete by matching a unique substring of the key material (safer when line numbers shift):
sed -i '/AAAAOBSOLETEKEYMATERIALFRAGMENT/d' ~/.ssh/authorized_keys
Step 5 — Confirm remaining count and fingerprints
wc -l ~/.ssh/authorized_keys
ssh-keygen -lf ~/.ssh/authorized_keys
The line count should match only the keys you still trust. Empty files mean password or out-of-band console access only—ensure you have console recovery before wiping the last key.
Step 6 — Fix ownership and permissions
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown -R "$(whoami):$(whoami)" ~/.ssh
For root:
sudo chmod 700 /root/.ssh
sudo chmod 600 /root/.ssh/authorized_keys
sudo chown -R root:root /root/.ssh
When to call Fixwebnode: You cannot tell which keys belong to live laptops or pipelines, or the only access path is a key you are about to delete. Remote specialists can inventory accounts and coordinate safe cutover.
Issue 2 — authorized_keys rewritten after you clean it
Symptom: You remove a rogue line, confirm with wc -l and ssh-keygen -lf, then hours later the same fingerprint returns.
Step 1 — Recheck immediately and note the timestamp
stat ~/.ssh/authorized_keys
ssh-keygen -lf ~/.ssh/authorized_keys
wc -l ~/.ssh/authorized_keys
Step 2 — Find processes and scheduled jobs that touch the file
sudo grep -R "authorized_keys" /etc/cron* /var/spool/cron 2>/dev/null
sudo systemctl list-timers --all
ps aux | grep -E 'ssh|ansible|puppet|chef|salt|cloud-init' | grep -v grep
Step 3 — Audit cloud-init and vendor agents (common on VPS images)
sudo grep -R "ssh_authorized_keys\|authorized_keys" /etc/cloud /var/lib/cloud 2>/dev/null | head -n 50
ls -la /etc/ssh/sshd_config /etc/ssh/sshd_config.d/ 2>/dev/null
Step 4 — Watch for live rewrites while you clean again
sudo apt-get update && sudo apt-get install -y inotify-tools
# Run in one session:
inotifywait -m ~/.ssh/authorized_keys
In another session, remove the bad line again with sed, then see which process fires. Disable or fix that source before the next login window.
Step 5 — Harden sshd so only expected key files apply
sudo grep -E '^(AuthorizedKeysFile|PubkeyAuthentication|PasswordAuthentication|PermitRootLogin)' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/* 2>/dev/null
sudo sshd -t && sudo systemctl reload sshd || sudo systemctl reload ssh
Confirm PubkeyAuthentication yes only where intended, and that AuthorizedKeysFile does not point at an unexpected path.
When to call Fixwebnode: The file keeps regenerating, configuration management is unfamiliar, or you suspect a rootkit-level restorer. That is beyond a single-file DIY edit.
Issue 3 — sshd logs show unauthorised successful key logins
Symptom: Auth logs list Accepted publickey for users or source IPs you do not recognise, even after you thought access was limited.
Step 1 — Read recent successful public-key acceptances
# Debian/Ubuntu often use journald + auth.log
sudo journalctl -u ssh -u sshd --since "14 days ago" | grep -i "Accepted publickey"
sudo grep -i "Accepted publickey" /var/log/auth.log 2>/dev/null | tail -n 100
On RHEL-like systems:
sudo grep -i "Accepted publickey" /var/log/secure 2>/dev/null | tail -n 100
Step 2 — Extract source IPs and usernames
sudo grep -i "Accepted publickey" /var/log/auth.log 2>/dev/null | awk '{print $1,$2,$3,$9,$11,$NF}' | tail -n 50
Compare IPs to your office, VPN, and CI egress ranges. Anything offshore or residential you do not own is a lead.
Step 3 — Tie logins back to key fingerprints where logged
sudo grep -iE "Accepted publickey|Found matching|publickey" /var/log/auth.log 2>/dev/null | tail -n 80
ssh-keygen -lf ~/.ssh/authorized_keys
sudo ssh-keygen -lf /root/.ssh/authorized_keys 2>/dev/null
Modern OpenSSH may log key fingerprints depending on version and LogLevel. Raise logging temporarily if you need more detail:
sudo grep -E '^LogLevel' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/* 2>/dev/null
# After intentional change and sshd -t:
sudo systemctl reload sshd || sudo systemctl reload ssh
Step 4 — Force remaining legitimate clients onto fresh keys
On each trusted workstation, generate a new key pair, install only the new public half, and remove the old line from the server:
ssh-keygen -t ed25519 -a 100 -f ~/.ssh/id_ed25519_$(hostname)_$(date +%Y%m)
# Copy only the .pub contents into the server authorized_keys, then:
ssh-keygen -lf ~/.ssh/authorized_keys
wc -l ~/.ssh/authorized_keys
Step 5 — Optionally restrict by user and network once clean
sudo ss -tlnp | grep -E ':22|:2222'
sudo fail2ban-client status sshd 2>/dev/null || true
Keep firewall and fail2ban as layers on top of a clean key file—not a substitute for removing the backdoor key.
When to call Fixwebnode: You see ongoing Accepted publickey events after cleanup, unknown local users, or signs of lateral movement. Full incident review is then appropriate.
Issue 4 — Duplicate key locations and weak .ssh permissions
Symptom: You cleaned one authorized_keys but logins still succeed; or sshd refuses keys because permissions are too open.
Step 1 — Find every authorized_keys-style file
sudo find /home /root -name 'authorized_keys*' -type f 2>/dev/null
sudo grep -R "AuthorizedKeysFile" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/ 2>/dev/null
Step 2 — Fingerprint each file you find
sudo find /home /root -name 'authorized_keys' -type f -exec echo '== {} ==' \; -exec ssh-keygen -lf {} \; -exec wc -l {} \;
Step 3 — Remove strangers per file, then normalise permissions
# Example for a deploy user after backup:
sudo sed -i '/ROGUEFRAGMENT/d' /home/deploy/.ssh/authorized_keys
sudo chmod 700 /home/deploy/.ssh
sudo chmod 600 /home/deploy/.ssh/authorized_keys
sudo chown -R deploy:deploy /home/deploy/.ssh
Step 4 — Verify sshd still accepts your remaining admin key
From a second terminal (keep the first session open):
ssh -o IdentitiesOnly=yes -i ~/.ssh/YOUR_TRUSTED_KEY -v user@your-server "echo OK && whoami"
If login fails, restore from the .bak file via provider serial/VNC console before closing your working session.
When to call Fixwebnode: Several service accounts, custom AuthorizedKeysCommand, or panel-managed keys make the layout unclear. Remote Linux support can map every path and leave you with a short trusted inventory.
End-to-end verification checklist
After addressing the issues above, run this short pass on each Linux host:
- Fingerprint all key files:
ssh-keygen -lfon every path fromfind. - Confirm counts:
wc -lmatches your staff and automation list only. - Permissions: directories
700, key files600, correct owners. - Logs: no fresh
Accepted publickeyfrom unknown IPs for 24–48 hours. - Persistence:
statmtime stable; no cron/cloud-init rewrite. - sshd config test:
sudo sshd -tthen reload only if clean.
ssh-keygen -lf ~/.ssh/authorized_keys
wc -l ~/.ssh/authorized_keys
stat ~/.ssh/authorized_keys
sudo journalctl -u ssh --since "1 day ago" | grep -i "Accepted publickey" || sudo grep -i "Accepted publickey" /var/log/auth.log | tail -n 20
sudo sshd -t
When DIY is enough vs when to book Fixwebnode
DIY is enough when you have console recovery, a clear list of legitimate keys, a single user (or few accounts), and logs go quiet after you delete strangers with sed and confirm via ssh-keygen -lf and wc -l.
Book a specialist when keys reappear, multiple servers share unknown fingerprints, root and deploy users both look dirty, sshd_config was changed, or you need a structured remote audit without flying onsite. Fixwebnode works as a direct remote Linux provider for Australian businesses—not a freelance marketplace—so you speak with the people doing the work.
Coverage and remote service areas are summarised on the service areas page. Most authorized_keys and sshd reviews are completed over SSH and provider console from wherever your VPS or hardware lives in Australia.
Get help cleaning SSH backdoors on your Linux server
If an unknown key might still be sitting in authorized_keys, do not stop at a password reset. Fingerprint the file, remove what you cannot own, verify the line count, and read the sshd logs—then get a second pair of eyes if anything still looks wrong.
Start a conversation with Fixwebnode for remote Linux server support focused on SSH key audits and persistent backdoor removal: Ubuntu Linux server support and bug fixing. Bring your current fingerprint list and a note of any unexpected Accepted publickey lines; we will work through cleanup and hardening on your hosts.