- #!/bin/sh
- ##
- ## Mass Useradd For Linux
- ## This script that extracts new user data from a delimited text file,
- ## and automatically generates new user accounts. It generates a random
- ## password for each login, and exports the new logins and passwords to
- ## a text file. Passwords automatically expire at first login. The
- ## input file format is "username: full name" (no quotes) for each
- ## line.
- ##
- ## Mass Useradd creates a "User Personal Group."
- ## The UID and the GID are the same. User's home directories
- ## are created with restrictive permissions, chmod 700.
- ## Mass Useradd uses standard Shadow Suite utilities.
- ## Values and behaviors are easily modifiable, according
- ## to the individual utility being called. It calls a companion
- ## script, mass_passwd, to set each user password. You should
- ## have received mass_passwd from the same source as mass_useradd.
- ##
- ## This script was created by Aaron Malone, and modified by
- ## Meredydd Luff, Peter Samuelson, and Kathryn Hogg.
- ## Many thanks!
- ## Carla Schroder wrote the documentation and pestered
- ## the aforementioned persons to modify the original script.
- ## Copyright (C) 2003 Carla Schroder
- ## carla at bratgrrl dot com
- ## This program is free software; you can redistribute it and/or
- ## modify it under the terms of the GNU General Public License
- ## as published by the Free Software Foundation; either version 2
- ## of the License, or (at your option) any later version.
- ##
- ## This program is distributed in the hope that it will be useful,
- ## but WITHOUT ANY WARRANTY; without even the implied warranty of
- ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ## GNU General Public License for more details.
- ## http://www.fsf.org/licenses/gpl.html
- ##
- ## Usage:
- ## # sh mass_useradd < inputfile >> new-passwords.txt
- ##
- PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:$PATH
- # Read a line of input.
- # the format of the input file must be like this:
- # userlogin : FirstName LastName
- # to use a comma-delimited file, change IFS=":$IFS" to IFS=",$IFS"
- while IFS=":$IFS" read username realname; do
- # First, weed out blank lines and #comments
- case "$username" in
- '' | \#*) continue ;;
- esac
- # this part reads /etc/passwd and /etc/group, and calculates
- # the next available UID and GID.
- # it starts at {id=1000}, change this to suit
- id=$({ getent passwd; getent group; } | cut -f3 -d: | sort -un |
- awk 'BEGIN { id=1000 }
- $1 == id { id++ }
- $1 > id { print id; exit }')
- # Now users are added to /etc/group, /etc/passwd,
- # and home directories with chmod 700 are created
- # Any of the groupadd, useradd, and chmod options
- # can be changed to suit
- groupadd -g $id $username
- useradd -m -c "$realname" -g $username -u $id $username
- chmod 700 /home/$username
- # Set the password. This calls another script from this toolkit,
- # mass_passwd, which can be used independently. mass_passwd outputs
- # the username, password and userid.
- $(dirname $0)/1mass_passwd -M $username
- done
|