The Error
Permission denied (publickey).The server accepts only public key authentication, and your key isn't being accepted.
Check If Your Key Is Being Offered
Run SSH with verbose output to see which keys are being tried:
ssh -v user@serverLook for lines like:
debug1: Offering public key: /home/you/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/you/.ssh/id_ed25519If no key is offered, SSH isn't finding your key file. Specify it explicitly:
ssh -i ~/.ssh/my_key user@serverVerify the Public Key Is on the Server
On the server, check that your public key exists in the authorized_keys file:
cat ~/.ssh/authorized_keysYour public key should be on a single line, starting with ssh-rsa, ssh-ed25519, or ecdsa-sha2-.
To add your key:
```bash # On your local machine, copy your public key cat ~/.ssh/id_rsa.pub
# On the server, add it to authorized_keys echo "ssh-rsa AAAA...your-key-here... user@host" >> ~/.ssh/authorized_keys ```
Or use ssh-copy-id:
ssh-copy-id -i ~/.ssh/id_rsa.pub user@serverFix Permission Issues
Wrong permissions are the most common cause. SSH is strict about this.
On the server:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keysOn your local machine:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsaAlso check ownership:
# On the server
ls -la ~/.ssh/
# Should show your user as owner
chown -R $USER:$USER ~/.sshCheck sshd Configuration
On the server, verify /etc/ssh/sshd_config allows public key auth:
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keysIf you change the config, restart sshd:
sudo systemctl restart sshdStrict Modes
If sshd has StrictModes yes (the default), it will reject keys if permissions are too open.
Check the logs for clues:
sudo tail -f /var/log/auth.log
# Or on RHEL/CentOS
sudo journalctl -u sshd -fTest with Verbose Logging
On the server, enable debug logging temporarily:
sudo /usr/sbin/sshd -d -p 2222Then connect to port 2222:
ssh -p 2222 user@serverThe server will print detailed debug info to help identify the issue.