Safely Fix SSH Permission Denied and Host Key Changed Errors
Check the correct SSH user, private key, authorized_keys, file permissions, and server fingerprint before repairing publickey or known_hosts errors.
Article by Phạm Minh Thiện
Front-end developer working directly with Next.js, NestJS, Docker, Nginx, and Ubuntu VPS deployments.
Reviewed on 7/21/2026.
Table of contents
SSH errors that look similar can have very different causes. Permission denied (publickey) means authentication failed; REMOTE HOST IDENTIFICATION HAS CHANGED means the server identity stored in known_hosts no longer matches.
Diagnose them separately and verify the host fingerprint before removing any trust record.
Fix Permission denied (publickey)
Start with the exact user, host, port, and key:
ssh -vvv -i ~/.ssh/id_ed25519 -o IdentitiesOnly=yes deploy@203.0.113.10
Verbose output should show which key is offered and whether the server accepts it. Common mistakes include:
- connecting as
rootwhile the key belongs todeploy; - using a different private key than the matching
.pubfile; - pointing to the wrong server or SSH port;
- placing the public key in the wrong user’s home directory;
- incorrect ownership or permissions on
.sshandauthorized_keys.
On the VPS, check:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown -R "$USER":"$USER" ~/.ssh
sudo journalctl -u ssh --since "10 minutes ago"
The user’s home directory must also be accessible to the SSH daemon. Check /etc/ssh/sshd_config for PubkeyAuthentication, AuthorizedKeysFile, and any AllowUsers or DenyUsers rules. Validate changes with:
sudo sshd -t
sudo systemctl reload ssh
Fix REMOTE HOST IDENTIFICATION HAS CHANGED
This warning can be a legitimate server rebuild or IP reuse, but it can also indicate a man-in-the-middle attack. Verify the new host key fingerprint through your VPS provider console or another trusted channel first.
After verification, remove only the old entry:
ssh-keygen -F 203.0.113.10
ssh-keygen -R 203.0.113.10
ssh-keygen -R '[203.0.113.10]:2222'
Reconnect and compare the displayed fingerprint with the value you verified. Do not “fix” this by setting StrictHostKeyChecking=no globally.
Windows known_hosts location
OpenSSH on Windows normally stores the file at $env:USERPROFILE\.ssh\known_hosts. Use the same ssh-keygen -R command from PowerShell after verifying the new fingerprint.
A safe recovery order
- Confirm the destination IP and port.
- Verify the host fingerprint when the warning is about host identity.
- Test the intended user and private key with verbose output.
- Check server-side key location and permissions through a console or existing session.
- Validate and reload SSH configuration.
- Test a fresh connection before closing the recovery session.
Never delete all known_hosts entries or disable host verification as a first response. Narrow changes preserve useful security signals.
Continue reading
Related articles
What Is an SSH Key? Secure VPS Login Without a Password
Create SSH keys on Windows, Linux, and macOS, add the public key to a VPS, configure an SSH alias and permissions, and fix publickey errors safely.
Read article →What to Do After Buying an Ubuntu VPS: 20 Production Setup Steps
A practical Ubuntu VPS checklist covering a sudo user, SSH keys, UFW, security updates, swap, backups, monitoring, and final checks before deployment.
Read article →GitHub Actions CI/CD: Automatically Deploy Node.js to a VPS
Create a secure GitHub Actions pipeline that builds, tests, and deploys Node.js to a VPS over SSH with secrets, health checks, concurrency, and rollback.
Read article →