LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 10-05-2007, 08:08 AM   #1
naumz
LQ Newbie
 
Registered: Oct 2007
Posts: 3

Rep: Reputation: 0
creating multiple users


Hi. I would like to create multiple users at one go. I read up on the command newusers and tried to use it. but the problem was, the created users could not login as they had no login profiles created in their home directories. I mean, the created user directories were blank. No bash profiles in them, nothing. So i suppose i could copy all these default files from a user created manually and start working or is there a better way?

In the first case, how can i copy the files to multiple directories? The home directories do not have anything common in their name except that they are all in the same directory.

Thank you very much for your help.
 
Old 10-05-2007, 08:37 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
I think the useradd command will do what you want. Using the various command line options to do different things. See the manual page for more details.
 
Old 10-05-2007, 08:43 AM   #3
naumz
LQ Newbie
 
Registered: Oct 2007
Posts: 3

Original Poster
Rep: Reputation: 0
no, the useradd command can add only one user at a time. And moreover the password has to specified in an encrypted form with the -p option. I want to create a whole batch of users (200+) at a go. When i use the newusers command for it with the syntax given in the man pages, i end up creating all the users, but none of them have login shells. It displays the shell in the etc/passwd file but when i try to login as any of the thus created users, it gives me an error saying that no login shell found. What could be the error here?

And abt the copying thing, i tried copying all the files (hidden and all) from a working user to one of these users' home directories but that didnt work either. So i guess I am now looking for some way to add hundreds of users at a time. I do not know much about scripting so i can't code them myself. Any help would be appreciated.

Thanks again.
 
Old 10-05-2007, 10:07 AM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
Write a file containing the list of user names and other details (e.g. comment, shell, skeleton directory and so on).

Write a shell script which iterates over this list. For each line it should also call makepasswd with the --crypt-md5 or --crypt option as appropriate for your system, saving the unencrypted password in a file with the username, which is cut up and given to users by whatever means you do that. Make sure the permissions on this file are such that only the root user can read or write it!

useradd should be called with the appropriate values and with the encrypted password value.

As long as you user the shell-internal echo command (note this is "print" if you use ksh, "echo" if you use bash), the un-encrypted password will not be visible in the process list.

I'm sure there are pre-written tools for this sort of thing, but it's good to know how to do it yourself.

A very simple version might look like this. Only the username, group and name are provided in the lilst of user file, which is called "userdata":
Code:
user1 users User One
user2 users User Two
user3 users User Three
And the script to process this would be something like this:
Code:
#!/bin/bash

IFS=" "

# Check the user_passwords file does not exist, fail if it does
if [ -a user_passwords ]; then
    echo "user_passwords file already exists, but should not"; 
    exit 1
else
    # create empty user_passwords file and make permissions safe
    touch user_passwords
    chmod 600 user_passwords
fi

# read data from userdata and make accounts accordingly.
while read user group comment; do
    makepasswd --crypt-md5 | while read pass passenc; do
        echo "user = $user   password = $pass" >> user_passwords
        echo "" >> user_passwords
        useradd -m -g $group -c "$comment" -p "$passenc" $user
    done
done < userdata
And run the program as root to make the accounts and create user_passwords which contains the information you will ultimately give to the users.

Make sure you run this program in a directory which is owned by root, else the owner of the directory might be able to remove, rename or otherwise mess with the user_passwords file. It's best done in root's home directory, and that is best set so only root can see inside it.

I hope that helps.

Also, please note that I have never actually done this operation myself (except just now as a test). I'm sure there are other ways to do it, and maybe a seasoned sysadmin will say my method is not good for some reason. Ho hum.
 
Old 10-05-2007, 04:29 PM   #5
naumz
LQ Newbie
 
Registered: Oct 2007
Posts: 3

Original Poster
Rep: Reputation: 0
thanks a lot. p.s. i don't care what any sysad says! btw, i was just experimenting and found another alternative. there's a chpasswd command to change passowrds in bulk and that can be used after creating users without passwords.
 
Old 10-05-2007, 05:36 PM   #6
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
Quote:
Originally Posted by naumz View Post
thanks a lot. p.s. i don't care what any sysad says! btw, i was just experimenting and found another alternative. there's a chpasswd command to change passowrds in bulk and that can be used after creating users without passwords.
Hey hey - I either never knew about it or forgot about it, probably the former... It's a good day when one finds out about new thing.
 
  


Reply

Tags
login, multiple


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple Autologins; Multiple Users; Multiple Sessions mrclisdue Linux - Desktop 1 09-26-2007 05:50 AM
creating multiple users sikkalgopal Linux - Newbie 3 07-06-2007 06:01 AM
Creating multiple users in Kmail with a single KDE user jonole Linux - Software 3 10-03-2004 12:36 AM
[FC2]Why does the users command display multiple users? Harkov Fedora 1 07-10-2004 09:24 PM
script for creating multiple users d3funct Programming 1 08-21-2001 05:22 PM


All times are GMT -5. The time now is 06:55 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration