I'm trying to manually install a daemon (Oracle Grid Engine) on my machine, and I would like it to run under an isolated account. What is the preferred way, using Directory Services, to add a "system" account to the local machine on OS X? Plenty of them exist in /etc/passwd (_www
, _dovecot
, etc.), but comments at the top of that file say that it isn't used except in single-user mode.
I'm running on 10.6, and do not require any special networked account management. I'm hoping for something simple--the equivalent of useradd
on nearly every other Unix-like OS.
EDIT: Updated Jan 9, 2014 for OS X Mavericks (suggestions from Dave, thanks!)
I wrote a bash script to do this. It will use the first unused uid which is less than or equal to 500 (daemon account uids on Mac OS X) that also has an identical unused gid.
Save the script to a file named
add_system_user.sh
and set it executable withchmod 755 add_system_user.sh
.Then let's say you want to add a daemon/system user called par. You would run this script like so:
sudo add_system_user.sh par
And you will get a system user called
_par
which is aliased topar
(the name you requested) and has a matching uid and gid (e.g. 499 or whatever it found).Here's the script:
I tried the script from par, and found a few issues. So I modified it for one specific userid and for OS X Mavericks (10.9).
I found that there was a couple extraneous records added to the User account under Mavericks -- a PasswordPolicyOptions and an AuthenticationAuthority record -- that needed to be removed to correctly mimic other builtin service user accounts (like _www).
I also added the Password and RealName records to the Group account.
I created a custom, one off, script just for a WSGI service account. Here's the updated script.
Note that after running this script the /etc/passwd and /etc/groups files are not updated. I believe they are updated on reboot.
dscl is the command you are looking for.
Here's an article that explains how to use dscl to create a user account.
osxdaily.com article
Here's a version of Dave's script, which also checks if the user/group exists before creating it:
and a script to delete user: