Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Add users via AppleScript, Perl and expect System
If you want a quick and easy Applescript which will add users (with group) and set the password, I've written just such a program. For all the details, check out this post on my blog. You can run this on the command line or via Apple Remote Desktop. It's kind of handy if you don't have access to the GUI and need one command to add a user.

[robg adds: This previous hint explained how to add users from the command line in 10.3, with some caveats in the comments as to some possible issues with the method.]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[9,723 views]  

Add users via AppleScript, Perl and expect | 2 comments | Create New Account
Click here to return to the 'Add users via AppleScript, Perl and expect' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Add users via AppleScript, Perl and expect
Authored by: madsteer on Feb 06, '07 07:01:26AM

Changing the password with the BSD passwd command, in my experience, breaks the connection between the user password and the user's login keychain. In fact, changing another users password in System Preferences also does.

the only way to change a user's password and have the keychain relationship maintained is to log in as that user, and then go to System Preferences and change that account's password.

This is really annoying if you have a seperate account to handle Admin tasks, so you can remove your primary accont from admin. I don't actually need to log in as my admin account to do any admin tasks, just change my admin password.

Anyway to command line, or other, script this to maintain the keychain relationship?



[ Reply to This | # ]
Add users via AppleScript, Perl and expect
Authored by: ephantom on Jun 26, '07 11:23:52AM

We are also looking for a way to change the keychain password via command line.


However here is a script we created and use for making new users via command line that others might find helpful:

--------------


#!/bin/tcsh

# Create a New OSX 10.x user

#-------------------------------------------------------------------------------
# Command: ./createuser <First Name> <Last Name> <Short Name> <Uid> <Shell>
#-------------------------------------------------------------------------------

#-------------------------------------------------------------------------------
# Example: ./createuser Bob Doe bob 520 tcsh
#-------------------------------------------------------------------------------



set first = $argv[1]
set last = $argv[2]
set login = $argv[3]
set number = $argv[4]
set shell = $argv[5]
echo " User's name is ${first} ${last}"
echo " User's login is ${login}"
echo " User's UID is ${number}"
echo " User's shell is /bin/${shell}"

echo " Creating the users account..."

sudo nicl / -create /users/${login} authentication_authority \;basic\;
sudo nicl / -create /users/${login} picture "/Library/User Pictures/Animals/Dog.tif"
sudo nicl / -create /users/${login} _shadow_passwd ""
sudo nicl / -create /users/${login} hint ""
sudo nicl / -create /users/${login} realname "${first} ${last}"
sudo nicl / -create /users/${login} _writers_hint ${login}
sudo nicl / -create /users/${login} uid ${number}
sudo nicl / -create /users/${login} _writers_passwd ${login}
sudo nicl / -create /users/${login} gid 20
sudo nicl / -create /users/${login} shell /bin/${shell}
sudo nicl / -create /users/${login} name ${login}
sudo nicl / -create /users/${login} _writers_tim_password ${login}
sudo nicl / -create /users/${login} passwd \*
sudo nicl / -create /users/${login} _writers_picture ${login}
sudo nicl / -create /users/${login} home /Users/${login}
sudo nicl / -create /users/${login} sharedDir Public

echo " Adding user to the staff group..."
sudo nicl / -merge /groups/staff users ${login}

echo " Creating the users directory..."
sudo ditto -rsrcFork "/System/Library/User Template/English.lproj" /Users/${login}
sudo chown -R ${login}:staff /Users/${login}

echo "Enter the users account password:"
sudo passwd ${login}

echo "Backing up netinfo"
set date = `date +%Y%m%d.%H%M`
sudo cp -pr /var/db/netinfo/local.nidb /var/db/netinfo/local.nidb.${date}

echo ""
echo " Account setup complete."
echo ""



[ Reply to This | # ]