User Tools

Site Tools


shell_tips:adding_multiple_users

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revision Both sides next revision
shell_tips:adding_multiple_users [2012/08/14 12:31]
ikahugu created
shell_tips:adding_multiple_users [2012/08/14 12:43]
ikahugu
Line 1: Line 1:
-1. Example of how to add 50 users+1. Example of how to add 50 users without password
  
  <code>  <code>
-for usernum in {1..50}; do  useradd -m user$usernum; done+$for usernum in {1..50}; do  useradd -m user$usernum; done
 </code> </code>
-This will create 50 users without password 
  
 2. You can generate passwords from the usernames 2. You can generate passwords from the usernames
 <code> <code>
-for usernum in {1..50}; do  useradd -m user$i; echo  "user$usernum" | passwd --stdin user$usernum; done+$for usernum in {1..50}; do  useradd -m user$i; echo  "user$usernum" | passwd --stdin user$usernum; done
 </code> </code>
  
Line 14: Line 13:
  
 <code> <code>
-for usernum in {1..50}; do  echo  `</dev/urandom tr -dc a-z | head -c 10`|passwd --stdin user$usernum ;done+$for usernum in {1..50}; do  echo  `</dev/urandom tr -dc a-z | head -c 10`|passwd --stdin user$usernum ;done
 </code> </code>
  
Line 20: Line 19:
  
 <code> <code>
-for usernum in {1..50}; do  useradd -m user$usernum; echo  "user$usernum" | passwd --stdin user$usernum; gpasswd -a "user$usernum" sshd; /bin/cp -f  /home/user/.bashrc /home/"user$usernum";done+$for usernum in {1..50}; do  useradd -m user$usernum; echo  "user$usernum" | passwd --stdin user$usernum; gpasswd -a "user$usernum" sshd; /bin/cp -f  /home/user/.bashrc /home/"user$usernum";done 
 +</code> 
 +5. With random passwords 
 +<code> 
 +$for usernum in {1..50}; do  useradd -m user$usernum;   
 +echo `</dev/urandom tr -dc a-z | head -c 10`|passwd --stdin user$usernum ;  
 +gpasswd -a "user$usernum" sshd;  
 +/bin/cp -f  /home/user/.bashrc /home/"user$usernum";done 
 +</code> 
 + 
 +**Note**: We have used /bin/cp to escape cp alias in bash; this is usually on Centos 
 + 
 +**Delete users** 
 +Remove the above users; including mailboxes and home folders  
 + 
 +<code> 
 +for usernum in {1..50}; do  userdel -r -f user$usernum; done
 </code> </code>
shell_tips/adding_multiple_users.txt · Last modified: 2012/08/14 12:43 by ikahugu