|  
 
 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: 
 
- 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)
 - Ask for their username
 - 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)
 - 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 
	
 -  You may want to set up the "useradd" bit with a function or two
 -  Set the password using passwd $username
 -  
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?)
 -  Ask them three questions:
  What is their real name? 
What is their Office Room Number? 
What is their Office Phone Number? 
 - Using that info, use the chfn command to set that information, 
remember to put "quotes" around the variables that might contain spaces
 - 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
 
  
   |