Adding new users

ira mendell ibm at bestweb.net
Mon Mar 25 20:06:04 PST 2002


Gerard Beekmans wrote:

> On Sat, Mar 23, 2002 at 09:25:49PM -0500, ira mendell wrote:
> > GROUP=100
> > HOME=/home
> > INACTIVE=-1
> > EXPIRE=
> > SHELL=/bin/bash
> > SKEL=/etc/skel
> >
> > as a side note when I looked at the new home directory created,  through
> > KDE in Redhat,  it showed the directory and files as GROUP="users"
> > and OWNER="1000"
> >
> > I think I'm close would adding a default such as USERS=100 to
> > etc/defaults work.
>
> See my other email I wrote (I didn't see this one else I'd have replied to
> this one instead).
>
> The /etc/login.defs defines the MIN and MAX userid's used. As you may know,
> you cannot use the same userid for two people. It's fine to use the same
> groupid for more than one person, but userid's have to be unique. If you
> want userid's to start at 100 edit the UID_MIN variable in the
> /etc/login.defs file.
>
> --
> Gerard Beekmans
> www.linuxfromscratch.org
>
> -*- If Linux doesn't have the solution, you have the wrong problem -*-
> --
> Unsubscribe: send email to listar at linuxfromscratch.org
> and put 'unsubscribe lfs-support' in the subject header of the message

Mr. Beekmans,
    Thank you for your replies.  By the time I realized you had replied I had
already poked around and found the login.defs file. I managed to figure out a
lot on mu own. You know it gets a little fustrating trying to find the answers
but between  the great people on this newsgroup and yourself you get a great
feeling when you figure it out.
    One gentleman "Speed" in a previous reply steered me to a good useradd
script.  I adapted his version to suit what I was trying to do.
-------------- next part --------------
#!/bin/sh
# Begin /usr/sbin/adduser
#
# adduser script for use with shadow passwords and useradd command.
# by Hrvoje Dogan <hdogan at student.math.hr>, Dec 1995.
# Modified by Patrick Volkerding, Oct 1997, Mar 1999, May 2000.
#
# This is a modified version of the Slackware-8.0 'adduser' script.
# Tweaked by Speed <cfi at highspeed.flyer.co.uk>, Feb 2002.
#
#----------------------------------------------------------------
# This version modified by ibm  <ibm at bestweb.net> 3-24-2002
# Thanks to Speed for sending me his version when I was trying
# configure my LFS 3.2 system. My goal was to make this script 
# act more like my Redhat7.2 host distribution.
# This worked with LFS 3.2...It's probably not nessessary to 
# make the  following changes but Redhat uses these defaults
# Edit /etc/login.defs....first under... 
#  'Min/max values for automatic uid selection in useradd' 
#               change   UID_MIN to 500
# Under  'Min/max values for automatic gid selection in groupadd'
#               change   GID_MIN to 500
# In /etc/default/useradd the 'GROUP' entry  should =500
# You should have a /etc/skel directory set up with whatever default 
# files that you want copied to the new users home directory
# This version will add a new user with a group of ths same name
# with a GUI and UID starting at 500. Any additional users will be
# incremented by 1.
#----------------------------------------------------------------

echo
echo -n "Login name for new user []: "
read LOGIN
if [ -z "$LOGIN" ]; then
  echo "You can't leave the login field empty."
  exit
fi
#-------------------------------------------------

echo
echo -n "Initial group for $LOGIN [$LOGIN]: "
read GID
if [ -z "$GID" ]; then
  GID=$LOGIN
fi
GGID="-g $GID"
#-------------------------------------------------

echo
echo "Additional groups for $LOGIN (seperated"
echo -n "with commas, no spaces) []: "
read AGID
GAGID="-G $AGID"
if [ -z "$AGID" ]; then
  GAGID=""
fi
#-------------------------------------------------

echo
echo -n "$LOGIN's home directory [/home/$LOGIN]: "
read HME
if [ -z "$HME" ]; then 
  HME="/home/$LOGIN"
fi
GHME="-d $HME"
#-------------------------------------------------

echo
echo -n "$LOGIN's shell [/bin/bash]: "
read SHL
GSHL="-s $SHL"
if [ -z "$SHL" ]; then
  GSHL="-s /bin/bash"
  SHL="/bin/bash"
fi
#-------------------------------------------------

echo
echo -n "$LOGIN's account expiry date (YYYY-MM-DD) []: "
read EXP
GEXP="-e $EXP"
if [ -z "$EXP" ]; then
  GEXP=""
fi
#-------------------------------------------------

echo
echo "A new account is about to be made. Here's what you entered so far:"
echo
echo
echo New login name: $LOGIN
#-------------------------------------------------

if [ -z "$GUID" ]; then
  echo New UID: [Next available]
else
  echo New UID: $ID
fi
#-------------------------------------------------

if [ -z "$GGID" ]; then
  echo Initial group: users
else
  echo Initial group: $GID
fi
#------------------------------------------------

if [ -z "$GAGID" ]; then
  echo Additional groups: [none]
else
  echo Additional groups: $AGID
fi
#------------------------------------------------

if [ -z "$GHME" ]; then
  echo Home directory: /home/$LOGIN
else
  echo Home directory: $HME
fi
#-----------------------------------------------

if [ -z "$GSHL" ]; then
  echo Shell: /bin/bash
else
  echo Shell: $SHL
fi
#------------------------------------------------

if [ -z "$GEXP" ]; then
  echo Expiry date: [no expiration]
else
  echo Expiry date: $EXP
fi
#------------------------------------------------

echo
echo
echo "If you wish to stop now, hit Control-C.  Otherwise, press"
echo "ENTER to go ahead and make the account."
read FOO
echo
echo Making new account........
#----------------------------------------------

/usr/sbin/groupadd $LOGIN
#----------------------------------------------

/usr/sbin/useradd $GHME -m $GEXP $GGID $GAGID $GSHL $LOGIN
if [ -d $HME ]; then
  chmod 711 $HME
fi
#--------------------------------------------------

echo
echo
echo -n "Enter the name of --> [$LOGIN] <-- if you wish []: "
read FULLNAME
if [ -z "$FULLNAME" ]; then
echo
echo "   No name will be added to password file "
echo
/usr/bin/passwd $LOGIN
echo "Done......"
else
#--------------------------------------------------

echo 
echo
echo "The following name ---> $FULLNAME <--- "
echo  " is being added to password file"
/usr/bin/chfn -f"$FULLNAME" $LOGIN
echo
/usr/bin/passwd $LOGIN
echo "Done..."
fi

# End /usr/sbin/adduser



















More information about the lfs-support mailing list