User Tools

Site Tools


shell_tips:adding_multiple_users

1. Example of how to add 50 users without password

$for usernum in {1..50}; do  useradd -m user$usernum; done

2. You can generate passwords from the usernames

$for usernum in {1..50}; do  useradd -m user$i; echo  "user$usernum" | passwd --stdin user$usernum; done

3. You can also generate random passwords

$for usernum in {1..50}; do  echo  `</dev/urandom tr -dc a-z | head -c 10`|passwd --stdin user$usernum ;done

4. Add users with passwords, assign to sshd group, and copy a similar .bashrc to each home folder

$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

5. With random passwords

$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

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

for usernum in {1..50}; do  userdel -r -f user$usernum; done
shell_tips/adding_multiple_users.txt · Last modified: 2012/08/14 15:43 by ikahugu