6.3 Shell Script - Creating User Accounts

The following describes using a shell script to create user accounts and user home folders.

Log in as "root" to the server that hosts the NetInfo master.  
Copy the script "mkusers.sh" into roots' home directory (/private/var/root/Documents).  
Start a new shell.  

Change directory to roots' home directory, type:

cd ~/Documents

 

Make sure that the execute flag is set on the script "mkusers.sh" by typing:

chmod u+x mkusers.sh

 
Launch a text editor.  

The "TextEdit" application defaults to "RTF" for new files.

To change the defaults to plain text, select "Preferences..." from the "TextEdit" menu.

 
Click on the "Plain text" radio button, then close down preferences.  
Create a new file.  

Create a text file containing a line for every user that gives the following information:

user_shortname,user_realname,password,
group

Note, if no password is specified on the line as follows:

user_shortname,user_realname,group

...then the user's password is generated using the command line utility babelpass.

babelpass generates passwords based on a language template file. See script for details.

If either babelpass or the language template file is not available, then the password is set to be the short name.

 

Save the file as "users.txt" in roots' home directory.

 
Quit the editor.  

Execute the "mkusers.sh" script and pass it the file "users.txt" as a parameter by typing the following:

~/Documents/mkusers.sh users.txt

The script will create Mac OS X netinfo user entries for every user specified in the file.

 

Now that the users are defined, we need to make sure that the any folders required by the users are available.

Copy the script "mkuserfldrs.sh" into roots' home directory (/private/var/root/Documents).

 

Execute the "mkuserfldrs.sh" script by typing the following:

~/Documents/mkuserfldrs.sh

This script will create the user home folder and any required subfolders for every user whose home is local to this server.

For this reason, the "mkuserfldr.sh" script should be run on every server that hosts user homes.

 
 

If the user home folder does not exist, this script creates it:
"user_name" (u=r/w,g=r/w,o=r)

The script then creates the following folders inside the users' home folder
"user_name/Sites" (u=r/w,g=r/w,o=r)
"user_name/Public" (u=r/w,g=r/w,o=r)
"user_name/Desktop" (u=r/w,g=r/w,o=none)
"user_name/Documents" (u=r/w,g=r/w,o=none)
"user_name/Library" (u=r/w,g=r/w,o=none)
"user_name/Movies" (u=r/w,g=r/w,o=none)
"user_name/Music" (u=r/w,g=r/w,o=none)
"user_name/Pictures" (u=r/w,g=r/w,o=none)

The script also creates the following (Macintosh Manager) folder within the mount folder:
"Users/Groups Folder/group_name/Hand In ƒ/user_name" (u=w,g=r/w,o=none)
(u=user_name,g=wheel)

Mac OSX server - tech notes - © 2002 by Mark J Swift - msw AT blackpool.ac.uk