summaryrefslogtreecommitdiff
path: root/mass_useradd
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2005-08-19 00:52:41 +0000
committerJonas Smedegaard <dr@jones.dk>2005-08-19 00:52:41 +0000
commit9ff011d44e6f0a663e9c067a853c1c5e4f5fee6e (patch)
tree19f05dd2077d324b420bb197d41db51feb098091 /mass_useradd
parent24b6ad269cd88f428bbe7f19497ccf3121622c60 (diff)
New script mass_useradd.
Diffstat (limited to 'mass_useradd')
-rwxr-xr-xmass_useradd78
1 files changed, 78 insertions, 0 deletions
diff --git a/mass_useradd b/mass_useradd
new file mode 100755
index 0000000..468453f
--- /dev/null
+++ b/mass_useradd
@@ -0,0 +1,78 @@
+#!/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