On Linux I use:
sudo useradd -r -p \* -s /sbin/nologin -c "Comment My Daemon,,," -d "/var/uuu" myuser
The next alternative must be more cross platform (if -r
option is not available):
sudo useradd -K UID_MIN=100 -K UID_MAX=499 -K GID_MIN=100 -K GID_MAX=499 -p \* -s /sbin/nologin -c "Comment My Daemon,,," -d "/var/uuu" myuser
Here:
password in /etc/shadow will be setted to *
. Without -p \*
it will be !
shell will be /sbin/nologin
(You can use /bin/false
too, but I think the /bin
may be mounted too late on some systems). So user can't login
-d
sets user's homedir
IMPORTANT NOTE
Here -r
creates a system user:
This flag is used to create a system account. That is, a user with a UID
lower than the value of UID_MIN
defined in /etc/login.defs and whose password does not expire. Note that useradd will not create a home directory for such an user, regardless of the default setting in /etc/login.defs. You have to specify -m
option if you want a home directory for a system account to be created. This is an option added by Red Hat.
Option -r
may not be present on your system. So to create a system user, that is not shown on your login screen, I think, you can use -K
option. Something like: -K UID_MIN=100 -K UID_MAX=499
. You can try option like:
-K UID_MAX=$(cat /etc/login.defs | grep ^UID_MIN | awk '{print $2}')
to automatically determine you UID_MAX
, but I've not tested on OS X. You'll need use SYS_UID_MAX
for UID_MIN
if it's uncommented in /etc/login.defs
The same is for GID_MAX
and GID_MIN
for the system group id. (See GID_MIN
and if uncommented SYS_GID_MAX
in /etc/login.defs to use as GID_MAX
)
useradd
starts adding id's at 1000, and the login managers won't show user id's below that, but everything above. so though it's not an answer to this question, it might be the resolution to the problem. please note that 1000 is arbitrary and may be lower or higher on your distribution. To fix just modify the user entry in/etc/passwd
to have a lower uid. Now for me to go ask similar question.