LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-24-2005, 01:22 AM   #1
LinuxGeek
Member
 
Registered: Jun 2002
Posts: 302

Rep: Reputation: 31
Automating Adding Users


I have a large number of users (100s) that I want to make accounts for on my machine. I'm trying to find the fastest way to automate their addition, including setting passwords for them. I have a default password list I want to use (yes, I know this isn't the best security in the world ). I've tried writing a small bash script to automate this but to no avail. I've also used the following commands:

newusers - the problem with this is that it doesn't copy the contents of /etc/skel (I also don't remember if it creates the home directories or not)

useradd - I tried it with the -p option but that should take it as encrypted + it doesn't even create the home directories for you.

I've heard that Expect is good at doing this sort of thing. Any ideas? Thanks for your time.
 
Old 01-24-2005, 03:05 AM   #2
masand
LQ Guru
 
Registered: May 2003
Location: INDIA
Distribution: Ubuntu, Solaris,CentOS
Posts: 5,522

Rep: Reputation: 69
useradd can create directory i think with the -d option

-d home_dir
The new user will be created using home_dir as the
value for the user's login directory.

regards
 
Old 01-24-2005, 08:23 AM   #3
LinuxGeek
Member
 
Registered: Jun 2002
Posts: 302

Original Poster
Rep: Reputation: 31
Thanks masand. But what about automating password entry? I'd rather not have to do passwd <username> 100s of times.
 
Old 01-24-2005, 09:11 AM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Code:
Make a temple for all new users when they are created:
I remove the .thunderbird so new users don't have the same email account setup. When the new user first logs in there may be a couple of messages about running programs as the first user. Just click on ignore and that message doesn't reappear.
rm -rf /etc/skel
mkdir /etc/skel
rsync -av --exclude='.thunderbird' /home/rctech/ /etc/skel

or

rm -rf /etc/skel
mkdir /etc/skel
cp -R /home/rctech/\. /etc/skel
rm -rf /etc/skel/.thunderbird
Here is my adduser from a file script.

The file /home/names.txt has the user names (lower case) , groups and the Linux/Samba password.
The Linux and Samba passwords are the same and the user should change them soon after login.
The groups can already exist.

For example.....

fred service 12qwaszx
sam hr 34erdfcv
joe maint 56tyghbn
sally sales 78uijkm

Code:
#!/bin/bash
#
# Ensure that root is running the script.
##
WHOAMI=`/usr/bin/whoami`
if [ $WHOAMI != "root" ]; then
echo "You must be root to add news users!"
exit 1
fi
#
clear
NEW_USERS="/home/names.txt"

cat ${NEW_USERS} | \
while read USER GROUP SMBPASS ; do
   
   groupadd ${GROUP} 2> /dev/null
   adduser ${USER} -g ${GROUP}

   (echo $SMBPASS; echo $SMBPASS) | passwd --stdin ${USER} > /dev/null
   echo Added user ${USER}

   smbpasswd -e ${USER} -w ${SMBPASS} > /dev/null
   (echo $SMBPASS; echo $SMBPASS) | smbpasswd -as ${USER}
   echo -e "${USER} = ${USER}" >> /etc/samba/smbusers
done

Last edited by homey; 04-05-2005 at 02:14 PM.
 
Old 01-24-2005, 01:18 PM   #5
LinuxGeek
Member
 
Registered: Jun 2002
Posts: 302

Original Poster
Rep: Reputation: 31
Thanks a lot homey. But from what I understand, you are configuring only samba passwords and not passwords for local / ssh access. I think the only difficulty in modifying this script would be to make the passwd command read the password from the script. Any ideas?
 
Old 01-24-2005, 05:30 PM   #6
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Edit: I modified the script to get the linux user password and the samba password from the names.txt file.

(echo $SMBPASS; echo $SMBPASS) | passwd --stdin ${USER} > /dev/null
echo Added user ${USER}

smbpasswd -e ${USER} -w ${SMBPASS} > /dev/null
(echo $SMBPASS; echo $SMBPASS) | smbpasswd -as ${USER}

Last edited by homey; 04-05-2005 at 02:16 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
adding new users Brian Du Preez Linux - Newbie 1 10-04-2005 12:33 PM
adding users tommytomato Linux - Newbie 15 09-01-2004 02:37 AM
Adding new users Fried Linux - Newbie 4 09-24-2001 10:37 AM
Adding users... philfighter Linux - General 3 07-23-2001 10:48 PM
adding Users hextex Linux - Newbie 5 06-08-2001 03:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration