is it possible to have a user account in Linux that can only login through its SSH public key?

I thought to simply do sudo passwd -l myuser and lock the account (so I don't need to generate some random and secure password) and allow to login only through SSH public key. Unfortunately this does not work (log says: User myuser not allowed because account is locked).


  • 1
    If the password is unknown and you only allow public key auth, for all intents and purposes, you've created an account that can only log in with keys. – NickW Apr 8 '14 at 13:36

Just generate a random string and pass it to the useradd command. If nothing else, useradd -p '*NP*' <userid> will do the trick.

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.