Has anyone created an OS X user at the command line rather than
through the netinfo interface? In some linux distributions there's
scripts (adduser or useradd) that allow you to create users at the
command line.
Is there anything similar with OS X.
In a similar vien, is their a command line way of listing all the
users?
(Using netinfo, I see about a dozen users (ex. mysql, game, postfix,)
and these names aren't in the /etc/passwd file.)
Thanks,
Nick
Mac OS X does not use the /etc/passwd file. It uses the NetInfo
database, which is also used to replace a lot of other unix data files.
The commands that deal with the NetInfo database start with ni. Type
"man ni" and then tab. You will see a list of commands starting with ni
(including ones that don't work with the NetInfo database.
If you want to see all the users in /etc/passwd format then type:
nidump passwd /
--
Matthew Smith
(to reply via email replace xxx with net)
Correspondingly, you can load a set of passwords in passwd format via
niload -d passwd . < [passwd-file]
So writing an adduser script should be simple enough: construct the
appropriate passwd line, then echo it into niload:
line=[extract the args and construct the passwd line]
echo $line | niload -d passwd .
--
d f-d
> So writing an adduser script should be simple enough
Don't bother.
#!/bin/zsh
# Script to add users by Stewart Walker
echo "Login account?"
read inp
if [ "x$inp" = "x" ]
then
echo "login needed"
exit
fi
log=$inp
echo "Full name?"
read inp
if [ "x$inp" = "x" ]
then
echo "Full name needed"
exit
fi
nam=$inp
echo "UID ? (next free after 100, this script does no checking)"
read inp
if [ "x$inp" = "x" ]
then
echo "UID needed"
exit
fi
uid=$inp
echo "Shell ? (/bin/zsh by default)"
read inp
if [ "x$inp" = "x" ]
then
inp="/bin/zsh"
fi
shl=$inp
echo "Home Dir? (/Local/Users/$log by default)"
read inp
if [ "x$inp" = "x" ]
then
inp="/Local/Users/$log"
fi
hom=$inp
echo "Can this user su to root (no by deault, otherwise type yes) ?"
read inp
if [ "x$inp" = "xyes" ]
then
gid=0
else
gid=20
fi
niutil -create / /users/$log
niutil -createprop / /users/$log shell $shl
niutil -createprop / /users/$log passwd ""
niutil -createprop / /users/$log realname $nam
niutil -createprop / /users/$log uid $uid
niutil -createprop / /users/$log gid $gid
niutil -createprop / /users/$log _shadow_passwd
niutil -appendprop / /groups/staff users $log
if [ "$gid" = "0" ]
then
niutil -appendprop / /groups/wheel users $log
fi
mkdir $hom
niutil -createprop / /users/$log home $hom
passwd $log
chown $log $hom
chgrp staff $hom
niutil -read / /users/$log
exit
--
Nicolas Seriot
www.seriot.ch
Check out man niutil, man niload, man nidump, etc.
David
Open a terminal window, and type "man nicl".
-jcr