3

This question already has an answer here:

I tried to disable login for a user account but got this error in debain:

useradd: unrecognized option '--disabled-login'

What is the equivalent of this command for useradd? Do I have to pick another shell, if so, which one?

marked as duplicate by slm, Anthon, Zelda, Timo, vonbrand Mar 3 '14 at 16:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    Why are you using useradd? --diabled-login is an option for adduser. – Graeme Mar 3 '14 at 13:56
1

If the user already exists, consider using usermod. You have more than 1 way to disable login. One is just to not set a password (* or x or anything invalid in /etc/passwd). The other is to set default shell of a user to /bin/false (some distros define /bin/NoShell, /bin/nologin or something).

usermod -s /bin/false -p x <username>
1

Pay special attention to the use of useradd & adduser and which distro you're on. The implementations are often different across distros. I usually use usermod or passwd instead:

For example, you can just lock the password:

$ sudo passwd -l <username>

To unlock:

$ sudo passwd -u <username> 

I'd also direct you to these Q&A's that already cover the various methods for "locking" a user's account.

From useradd's man page:

--disabled-login
       Do  not  run passwd to set the password.  The user won't be able
       to use her account until the password is set.
  • 'cmon this is much more "hacking way" that my one. From man pages: "Note that the account is not fully locked - the user can still log in by other means of authentication such as the ssh public key authentication." – stderr Mar 3 '14 at 14:52
  • @stderr - no way. This method or usermod are the prescribed methods. Depends on how much disabling you want to do. – slm Mar 3 '14 at 15:48
0

Use nologin as the default shell:

useradd --shell /usr/sbin/nologin [...]

*This path is on rpm based packages, not sure if debian has the same.

  • 1
    It does, the above syntax is valid. Although adduser should be preferred where possible. – Graeme Mar 3 '14 at 14:03
  • This is a hacky way to do it, best not to use this method. – slm Mar 3 '14 at 14:06

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