SSHD Error: 'Authentication refused: bad ownership or modes for file' — Cause, Fix, and Troubleshooting Guide
Fix sshd 'Authentication refused: bad ownership or modes for file': StrictModes rejects group/world-writable home, .ssh, or authorized_keys. Fix perms.
- #security
- #hardening
- #troubleshooting
- #linux
- #ssh
Stuck on this DevOps Security & Hardening error? Get the free incident triage checklist
A one-page PDF — the exact steps to isolate, fix, and verify a production error like this one. No spam, unsubscribe anytime.
What this error means
Public-key login failed because sshd, with StrictModes enabled, refuses to trust an authorized_keys file (or the directories leading to it) when the permissions or ownership are too loose. If another user could write to your home, .ssh, or authorized_keys, they could inject a key — so sshd ignores the file entirely.
Authentication refused: bad ownership or modes for file /home/deploy/.ssh/authorized_keys
This is logged server-side in /var/log/auth.log (or /var/log/secure); the client just sees Permission denied (publickey). The fix is to tighten ownership and modes, not to weaken sshd.
How it manifests on the host
- Key-based login fails with
Permission denied (publickey)even though the key is correct. - Server logs show
Authentication refused: bad ownership or modes for file ...or... for directory .... - It broke after restoring a home directory from backup, changing usernames/UIDs, or a careless
chmod -R. - One user is affected while others log in fine.
System configuration causes
- World/group-writable home or
.ssh.StrictModesrejects the whole chain if any parent is group/other-writable. - Wrong ownership.
authorized_keysor.sshis owned by root or a different UID after a restore oruseraddmismatch. - Loose
authorized_keysmode. The file is0644+group-write or worse. - Home restored with broad ACLs or a default umask that left group-write on.
- Shared home via NFS with squashed/incorrect ownership.
Interrogating the host
# Read the exact server-side reason
sudo grep -E 'Authentication refused|bad ownership' /var/log/auth.log | tail # or /var/log/secure
# Inspect the full ownership/mode chain for the user
ls -ld /home/deploy /home/deploy/.ssh /home/deploy/.ssh/authorized_keys
# Is StrictModes on? (default yes)
sudo sshd -T | grep -i strictmodes
# Any ACLs widening access beyond the mode bits?
getfacl /home/deploy/.ssh 2>/dev/null
sshd requires: home not group/other-writable, .ssh = 700, authorized_keys = 600, all owned by the user.
Remediation
1. Correct ownership and modes for the whole chain:
sudo chown deploy:deploy /home/deploy /home/deploy/.ssh /home/deploy/.ssh/authorized_keys
sudo chmod 755 /home/deploy # or 750; must NOT be group/other-writable
sudo chmod 700 /home/deploy/.ssh
sudo chmod 600 /home/deploy/.ssh/authorized_keys
2. Strip over-broad ACLs if getfacl showed extra write grants:
sudo setfacl -b /home/deploy/.ssh /home/deploy/.ssh/authorized_keys
3. Verify from the server log on the next attempt:
sudo tail -f /var/log/auth.log # attempt the login again; the refusal should be gone
4. Keep StrictModes on. Do not disable it as a workaround — it is a genuine security control. Fix the permissions instead.
Hardening the host
- Never set
StrictModes noto “fix” this — it lets any writable-home vector plant an authorized key. - A group-writable home directory is enough to trigger this even when
.sshitself looks correct; check the whole path. - Watch UID mismatches after migrations/restores — files can carry a numeric owner that no longer maps to the user.
- On NFS-mounted homes, confirm the export does not squash ownership in a way that trips StrictModes.
Related system errors
- SSH ‘Permission denied (publickey)’ Error Guide
- SSH ‘UNPROTECTED PRIVATE KEY FILE’ Permissions Error Guide
- Hardening SSH Access to Production Servers with AI
Fixed it? Get 500 DevOps Security & Hardening & DevOps AI prompts — free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.
Stuck on this? Start guided troubleshooting
Open an interactive diagnostic session with this error already loaded. Work a step-by-step plan, record what each check returns, land on a root cause, and export a clean incident summary — no account needed to start.
Did this fix your issue?
Solved it a different way?
Share the fix that worked for you — reviewed, then published to help the next engineer.
That looks like it may contain a secret (key, token, password, or connection string). Please remove it — a note with a detected secret can’t be published.
Thanks — that helps. Published notes appear after a quick review.
Trending errors this week
The error guides other engineers are actually reading right now.
- 1mount: wrong fs type, bad option, bad superblock
- 2Docker 'failed to set up container networking': Fix the Bridge and IP Pool
- 3Docker 'failed to create shim task': How to Fix the containerd Runtime Error
- 4Transport endpoint is not connected
- 5modprobe: FATAL: Module not found
- 6mount: wrong fs type, bad option, bad superblock
Get 500 Battle-Tested DevOps AI Prompts — Free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.