logo © 1996 Phil Waclawski
Felitaur Site
Offerings
About Me
Crafts
Services
ftp files
Help Files
What's New?
Home Page
Other Links
Anatomy &
Physiology
Arthropods
Biology
Computers
Ferrets
Fun Links
Internet
Linux
S.C.A.
Win 95/NT
Comments or
Suggestions
webmaster@ felitaur.com
   
New User Script
Lecture Overview Index | Linux SysAdmin Homepage

Creating new users, adding them to groups, giving them the files they need and permissions to various commands is an annoying job. Previously we used the information on Managing Users and Groups to do the User/Group assignment where you ended up having to keep track of way too many things. And while the "user manager" GUI tool from RedHat does ok, you don't always have a GUI handy.

Purpose:
To automate the rather complicated process of adding and configuring user accounts. (And get a better feel for shell scripting as a whole)

Requirements:

  1. The whole thing should be a big loop, so at the end it asks them if they want to add ANOTHER user. (Don't ask them when they first start the script)
  2. Ask for their username
  3. Ask them what type of user (adm, backup, account) using a select style menu (and also set the skel directory, will need to use an if statement due to the account group using skel, while adm uses adm, and backup uses backup)
  4. Within a while loop, try to create the user, one possible method for doing so would be:
    useradd -m -k /etc/$skeldir -g $group $username
    worked=$?
    while [ $worked != 0 ]; do
    echo "Sorry, that user already exists"
    echo "Please enter a unique username"
    #Note, we don't give them a chance to change user type here
    #which could be a mistake
    read username
    useradd -m -k /etc/$skeldir -g $group $username
    worked=$?
    done
  5. You may want to set up the "useradd" bit with a function or two
  6. Set the password using passwd $username
  7. Add them to the appropriate line in the /etc/group file
    use gpasswd -a $username $group (where you ask which group to add them to via a select statement?)
  8. Ask them three questions:
    What is their real name?
    What is their Office Room Number?
    What is their Office Phone Number?
  9. Using that info, use the chfn command to set that information, remember to put "quotes" around the variables that might contain spaces
  10. Set an age on their passwords by using chage, where the Maximum days of the password is 90, the warning is set to 10 days and you do this all on one command line, ending with $username