How to create an unprivileged user in CentOS?

I think I should link here two answers from serverfault:

  • how do i duplicate the nobody user? and
  • Create restricted user on Debian server ( btw, it was moved to serverfault from stackoverflow, just recently -- and possibly could have been moved to this site as well )

Basically -r means "set account as a system one" -- "no expiration", etc -- and the full spell may look like

useradd -s /bin/false -r <username>

or

useradd -s /usr/sbin/nologin -r -M -d /dev/null <username>

or similar )

NB. For things like samba one may also want to provide this user with a password and may be also add /usr/sbin/nologin to /etc/shells :

# which nologin >> /etc/shells

NB(2): as per OrangeDog's comment: -r actually implies -M, so -M is not strictly necessary.

PS. And yes, looking for the same thing at serverfault, askubuntu -- and here -- seems a bit odd to me; is there a way to run a meta-search on, say, all stackoverflow sites ?


From here (centos.org)

useradd (which is the actual binary the runs when you call adduser, it just behaves differently. See here about that.) has an flag -r which is documented as follows:

-r   Create a system account with a UID less than 500 and without a home directory

Which sounds like what you want to do.