nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

How to create multiple user account?

This is a discussion on How to create multiple user account? within the Shell scripting forums, part of the Development/Scripting category; I found the link to create multiple user account by typing out all the account. But how to create using ...

Register free or login to your existing account and remove all advertisements.


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-08-2007, 08:19 PM
Junior Member
User
 
Join Date: Jun 2007
OS: Debian
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
droidwork is on a distinguished road
Default How to create multiple user account?

I found the link to create multiple user account by typing out all the account. But how to create using linux shell scripting if i want to create 50 account which are almost the same but only difference is the user number and some other number is different which is in running order?

Eg.
First user will have the following details:
Login name: user00
Password: pwd00
UID: 1000
GID: 123
Informational name: “Student Index 00”
Home directory: /home/SI00
Login shell: /bin/sh

the last user will have the following details:
Login name: user49
Password: pwd49
UID: 1049
GID: 123
Informational name: “Student Index 49”
Home directory: /home/SI49
Login shell: /bin/sh

Last edited by droidwork; 06-08-2007 at 08:25 PM.
Reply With Quote
  #2 (permalink)  
Old 06-09-2007, 12:39 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,668
Thanks: 11
Thanked 240 Times in 180 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

You need to use newusers command and a text file with this info.
data.txt file
Code:
user00:pwd00:1000:123:Student Index 00:/home/SI00:/bin/sh
user01:pwd00:1001:123:Student Index 01:/home/SI01:/bin/sh
.....
...
..
user49:pwd49:1049:123:Student Index 49:/home/SI49:/bin/sh
Use following command to create above file:
Code:
for u in $(seq 00 05); do echo "user${u}:pwd${u}:$(expr 1000 + $u):123:Student Index ${u}:/home/SI${u}:/bin/sh"; done > data.txt
Run command
Code:
newusers data.txt
And you are done. more info @ my blog post: Linux: How to create multiple users accounts in batch | nixCraft

PS: If you are doing this first time, make a backup of all all password related files aka /etc/passwd, /etc/group, /etc/shadow and others
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 06-09-2007, 06:07 AM
Junior Member
User
 
Join Date: Jun 2007
OS: Debian
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
droidwork is on a distinguished road
Default

thank you.. lets say i wan to increase the user to say 80, which value should i change?
Reply With Quote
  #4 (permalink)  
Old 06-09-2007, 06:30 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,668
Thanks: 11
Thanked 240 Times in 180 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

change seq parameters from 00 05 to 00 49
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #5 (permalink)  
Old 06-10-2007, 03:12 PM
Junior Member
User
 
Join Date: Jun 2007
OS: Debian
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
droidwork is on a distinguished road
Default

sorry, i dont really get the code.. how come when create 50 user is 00 05 and 80 user is 00 49? Can explain the code part by part?

Last edited by droidwork; 06-10-2007 at 03:15 PM.
Reply With Quote
  #6 (permalink)  
Old 06-12-2007, 05:11 PM
raj's Avatar
raj raj is offline
Senior Member
User
 
Join Date: Jun 2005
Location: Hyderabad
OS: Fedora, Debian Linux
Posts: 307
Thanks: 42
Thanked 8 Times in 8 Posts
Rep Power: 6
raj will become famous soon enough raj will become famous soon enough
Default

Quote:
Originally Posted by droidwork View Post
sorry, i dont really get the code.. how come when create 50 user is 00 05 and 80 user is 00 49? Can explain the code part by part?
00-05 will create only 6 user from 00,01...05
00-49 wil create 50 users from 00,01,02..49

In short use
Code:
for u in $(seq 00 49); do echo "user${u}:pwd${u}:$(expr 1000 + $u):123:Student Index ${u}:/home/SI${u}:/bin/sh"; done > data.txt
__________________
Raj
Linux rulz.
I have never turned back in my life ; I shall not do so today.. haha
Reply With Quote
  #7 (permalink)  
Old 06-12-2007, 05:28 PM
Junior Member
User
 
Join Date: Jun 2007
OS: Debian
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
droidwork is on a distinguished road
Default

somehow i cant get it to work.. it create only 1 funny account and not.. mayb can someone teach me step by step?

i write the code in vi data.txt.. then after :wq!, use newusers data.txt.. is this the right way?

Last edited by droidwork; 06-12-2007 at 05:31 PM.
Reply With Quote
  #8 (permalink)  
Old 06-12-2007, 05:38 PM
raj's Avatar
raj raj is offline
Senior Member
User
 
Join Date: Jun 2005
Location: Hyderabad
OS: Fedora, Debian Linux
Posts: 307
Thanks: 42
Thanked 8 Times in 8 Posts
Rep Power: 6
raj will become famous soon enough raj will become famous soon enough
Default

Noop..

Login as root user

goto /tmp
Code:
cd /tmp
To create 00-49 user type command:
Code:
for u in $(seq 00 49); do echo "user${u}:pwd${u}:$(expr 1000 + $u):123:Student Index ${u}:/home/SI${u}:/bin/sh"; done > data.txt
Now you will see a file called data.txt. No need to create this file using vi text editor. It is genrated for you using above shell for loop.

Now just add new users
Code:
newuser data.txt
And you are done! Now user user1 can login with pwd1 and so on.
__________________
Raj
Linux rulz.
I have never turned back in my life ; I shall not do so today.. haha
Reply With Quote
  #9 (permalink)  
Old 06-12-2007, 06:35 PM
Junior Member
User
 
Join Date: Jun 2007
OS: Debian
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
droidwork is on a distinguished road
Default

thank you very much.. anyway can tell me what does $(expr 1000 + $u): do? i know u is for the value.. and 1000 is the starting.. but what does expr for?

Last edited by droidwork; 06-12-2007 at 06:41 PM.
Reply With Quote
  #10 (permalink)  
Old 06-12-2007, 09:17 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,668
Thanks: 11
Thanked 240 Times in 180 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Quote:
Originally Posted by droidwork View Post
thank you very much.. anyway can tell me what does $(expr 1000 + $u): do? i know u is for the value.. and 1000 is the starting.. but what does expr for?
Use to evaluate expressions such as expr 1 + 2 = 3

ARG1 + ARG2 arithmetic sum of ARG1 and ARG2

If $u=2, expr 1000 + ${u} = 1002

Read man page of expr for upto-date information.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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


Similar Threads

Thread Thread Starter Forum Replies Last Post
Create new user account in Ubuntu Linux from command line sweta Getting started tutorials 3 02-07-2010 01:15 PM
Unable to create user vaibhav.kanchan Getting started tutorials 3 12-07-2007 11:46 AM
how to create super user click007 Getting started tutorials 12 08-28-2007 09:14 PM
HP UX creating user account with SAM - it is easy to use rockdalinux HP-UX 0 12-20-2006 03:01 PM
how to create multiple file in a single command selvam Shell scripting 3 07-26-2006 02:01 AM


All times are GMT +5.5. The time now is 04:40 PM.


Powered by vBulletin® Version 3.8.4 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2009 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38