#!/bin/sh # # the "addnewuser" script is meant to be an alternative to # the "adduser" script. # # Written by: Fred Fenner techhead@linuxtoolbox.com # # NOTE: This script does NOT mask passwords during data entry. # # Late update: 21-Jul-2001 # # http://linuxtoolbox.com/addnewuser.txt # clear echo echo -n "Login name for new user (3 to 8 chars) []: " read LOGIN if [ -z "$LOGIN" ]; then echo echo "You cannot leave the LOGIN field empty.";exit fi tmp_var=${#LOGIN} if [ $tmp_var -lt 3 ] || [ $tmp_var -gt 8 ]; then echo echo "That LOGIN name is $tmp_var chars long.";exit fi echo echo -n "Password for $LOGIN (4 to 8 characters) []: " read PASS_WORD if [ -z "$PASS_WORD" ];then echo echo "You cannot leave the PASSWORD field empty.";exit fi tmp_var=${#PASS_WORD} if [ $tmp_var -lt 4 ] || [ $tmp_var -gt 8 ]; then echo echo "That PASSWORD is $tmp_var chars long";exit fi # # does the user account already exist? # if [ $(grep -c "^$LOGIN:" /etc/passwd) -eq '0' ]; then echo echo "If the information below is _not_ correct" echo "then press to exit and run" echo "\"addnewuser\" again." echo echo "Otherwise press to continue" echo echo "User account name: $LOGIN" echo "User's password: $PASS_WORD" echo read DUMMY # # useradd [-c comment] [-d home_dir] # [-e expire_date] [-f inactive_time] # [-g initial_group] [-G group[,...]] # [-m [-k skeleton_dir]] [-s shell] # [-u uid [ -o]] login # # user with telnet access # useradd -g 100 -d /home/$LOGIN -s /bin/bash -p x $LOGIN # # user without telnet access useradd -g 100 -d /home/$LOGIN -s /bin/noshell -p x $LOGIN # # NOSHELL can be found at http://linuxtoolbox.com/noshell.tgz # echo "$LOGIN:$PASS_WORD" | chpasswd mkdir /home/$LOGIN chmod -c 700 /home/$LOGIN chown -Rc $LOGIN /home/$LOGIN chgrp -Rc 100 /home/$LOGIN echo echo "User $LOGIN has been added." echo else echo echo "$LOGIN already exists" echo echo "run \"addnewuser\" again." echo fi # end of script