I need to add new users who are only supposed to be usable through SSH. When adding a user, they get added to the shadow file with an exclamation mark (!) instead of an asterisk (*), so they are "disabled" and sshd does not allow them to be used.

Is there a way to add a user without a password that is enabled by default?

I have tried using busybox' adduser command and it adds them with a !. Similarly, Gentoo's default useradd command will add them with a !.

| improve this question | | | | |
  • 3
    adduser <username> --disabled-password - just make sure to also use the --home and --shell options if they need a home directory and login shell as adduser doesn't create them by default. – ResetACK Oct 9 '19 at 13:25
  • @ResetACK Looks like my system (Gentoo-based) doesn't have the adduser command, and busybox' adduser doesn't use --disabled-password. On my Ubuntu VM it added it correctly though. – user Oct 9 '19 at 13:41
  • You might be SOL then :) what happens if you remove the ! from the shadow file? Can the user log in without a password? – ResetACK Oct 9 '19 at 13:47
  • 1
    @ResetACK Yes, manually editing the shadow file will make the account usable, but I'm trying to avoid that since automating will increase the amount of times I can screw something up. I figured out what I was doing wrong with the * though, so it seems to be working now. – user Oct 9 '19 at 13:49

Looks like I can specify the encrypted password to add the user with

useradd -p '*' testuser

It wasn't working previously because I forgot that the shell tried to expand the asterisk when I was missing the single quotes.

It looks like I could also use

usermod -p '*' testuser

on an existing user to set the password to an asterisk as well.

| 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.