Welcome to Geek Times!
spacer
Mac OS X: Creating a new user from the command-line
Find on this site:


home
search
archive
about

.
Creating a new user from the command-line
21 February 2005

When you want to install a package which needs its own, unpriviledged, user, you can always do it from the System Preferences. But what if you want to use the command-line?

I'm not sure from where this script originated, but I reproduce it here because it's been useful to me.

#!/bin/sh
echo "Enter username:"
read newuser
echo "Enter the full name for user $newuser's:"
read long_name
echo "Will $newuser an Admin user (y/N)?"
read is_admin
new_uid=`nidump passwd . | awk -F: '{print $3f}' | sort -n|tail -1`
new_uid=`expr $new_uid + 1`
nicl . -create /users/$newuser
nicl . -create /users/$newuser uid $new_uid
nicl . -create /users/$newuser realname "$long_name"
nicl . -create /users/$newuser passwd ""
nicl . -create /users/$newuser gid 20
nicl . -create /users/$newuser shell "/bin/tcsh"
nicl . -create /users/$newuser home "/Users/$newuser"
nicl . -create /users/$newuser _writers_passwd $newuser
passwd $newuser
ditto /System/Library/UserTemplate/English.lproj /Users/$newuser
chown -R $newuser:staff /Users/$newuser
nicl . -read /users/$newuser
if [ "$is_admin" = Y -o "$is_admin" = y ]
then
nicl . -append /groups/wheel users $newuser
nicl . -append /groups/admin users $newuser
nicl . -read /groups/wheel
nicl . -read /groups/admin
fi

I saved this as ~/bin/addu and then did

chmod ~/bin/addu rehash

This page is copyrighted 1993-2006 by Michael 'Mickey' Sattler, some rights reserved via the Creative Commons License. Questions and comments? Send email to the Geek Times Webmaster. (Domain and web content hosting at 1and1.)
email