I was reading about passwordless authentication with ssh. So I made a key and published it to my Ubuntu server, and it worked well.

Then decided to lock my password with passwd -l lucas, and I was not longer able to use sudo. I was thinking that sudo would also be without a password.

My question now is: how can I regain the ability to use sudo?


After running passwd -l on a user, that user can't set their password (until after it's set back to something usable).

Since you cannot use sudo, you'll need to reset your user account password, the same way as if you'd just forgotten what it was:

Then you can use sudo again, and you can set PasswordAuthentication no as explained in steeldriver's answer.

  • Thank you! it's setup now. I added in root mode NOPASSWD to sudo for my main user – Lucas Crijns Aug 22 '14 at 19:57

You will likely need to login to a root shell via the recovery console in order to re-enable your account password. After that, you can disable password login for ssh specifically by setting

PasswordAuthentication no

in the sshd_config file, and leave the account password enabled for local access (including running sudo once you have logged in via SSH using keys)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.