Troubleshooting SSH Key Permission Denied on Digital Ocean
If you're trying to connect to your Digital Ocean droplet using SSH and encounter a "Permission denied (publickey)" error, it can be very frustrating. Fortunately, the solution is often straightforward. This helps you ensure that your SSH keys are set up correctly for access.
1. Ensure Correct Key Pair Configuration
First and foremost, confirm that the correct SSH keys are configured in your Digital Ocean account. Make sure that the public key exists in your droplet's authorized keys:
cat ~/.ssh/authorized_keys
If your public key isn't listed, you’ll need to add it.
2. Check File Permissions
SSH can be particular about file permissions. Ensure your private key is secured:
chmod 600 ~/.ssh/id_rsa
Also, verify the permissions for the .ssh directory:
chmod 700 ~/.ssh
3. Correct User Name
When SSHing into your droplet, you need to specify the right username. For example, if you are using a standard Ubuntu droplet, the username should be root or ubuntu depending on how you set it up:
ssh root@your_droplet_ip
4. Ensure the SSH Agent is Running
If you use an SSH agent, check if your key is added using:
ssh-add -l
If your key isn’t listed, simply add it:
ssh-add ~/.ssh/id_rsa
Final Note
By following the steps outlined above, you can generally resolve the "Permission denied (publickey)" issue with SSH on Digital Ocean. Always ensure your keys are managed and configured properly to avoid interruptions in your access.