Linux下批量添加用户

     Linux shell 自学笔记之批量添加用户

  
  
  
  
  1. #!/bin/bash  
  2. #This shell is used to add users
  3. for loop in `cat users`  
  4. do  
  5.         useradd -m $loop  
  6.         echo $loop":"$loop >> userpwd  
  7.         chpasswd < userpwd 
  8. done  
  9. rm -f userpwd

   注释 ① users 文件为用户名文件,每个用户名独占一行;

        ② userpwd 文件为临时密码文件,为 chpasswd 命令提供数据源;

        ③ chpasswd 命令可将用户明文密码加密为密文,但要求数据源文本格式为“用户名:密码”,且用户名必须是已创建用户,故 useradd 步骤在前;

        ④ 以此脚本执行成功后,用户登录密码为其本人用户名。

你可能感兴趣的:(linux,shell自学笔记)