Question
Error Permission denied (publickey) when I try to ssh
Note from DigitalOcean Community team:
The user @intalix has provided a popular answer to this question here: https://www.digitalocean.com/community/questions/error-permission-denied-publickey-when-i-try-to-ssh?answer=44730
Recently I threw out my old linux laptop and set everything up again in my new laptop. The only trouble I have now is not being able to log in to my DO instance via ssh. This instance had one ssh key setup before and in the sshd config it had permitrootlogin set to no. So I created a new ssh key to be able to login from this new laptop.
$ ssh-keygen -t rsa -C "gitlab" -b 4096
Then added the public key this to the instance. Now I try to login
$ ssh user@server
I get asked password for this user. I am able to login using the password. This isn’t how I was logging in before. I used to type my ssh passphrase. So I thought this may be because this is a new key and I disabled password authentication in sshd config. After this, I get the error
$ ssh user@server
Permission denied (publickey)
I checked online and set the permission to .ssh folder to 700. Still I get the same error. I can access the online console of the instance, but don’t know what to do.
How do I resolve this?
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×
I have the same problem. It worked for me in one server but when I tried the same process in other server it is saying “permission denied (publickey)”.
Forunderstanding, I can log into x.x.x.216 but not into x.x.x.215 . actually both servers have everything i.e config same .
can anyone say why its happening.
To me, works changing (Ubuntu 18.04):
then, restart ssh service:
Thanks!
This solution worked like a charm! thanks
Thank you @RildomarLucena that worked perfectly!
My setup had PasswordAuthentication set to “no”, changed to “yes” and I was able to install ServerPilot.
This saved me! I’ve created dozens of droplets before but never had this issue until now. Thank you so much!!!
@RildomarLucena That may work for other cases, but that is how to switch to password authentication, not how to fix public key authentication. Also, if you have enabled public key authentication (which is what causes the error in the question), there is no way to get in and do that solution. See my reply to thomasalwyndavi for the solution. This is a duplicate of permission denied after creating droplet using ssh keys where I found clivestrydom’s correct answer (note that you must login via
ssh **root**@xxx.xxx.xxx.xx
not user, since only root exists after droplet creation and/or is the only user that has the public key you uploaded to the droplet during creation).Your problem is that the “owner” of this instance(copy) of the “xxx-key.pem” file is set to root. All you have to do is grant ownership of the file to your current user on the system you are on.
do:
sudo chmod myusername xxx-key.pem
and thats it!
You will have to do this anytime you copy the file to a new system