Linux Bulk Add users and bulk change passwords

Source: Internet
Author: User

First, batch create users
Batch creation of users can be achieved by command newusers.
The use of this command is NewUsers file.txt (a text file)
Storing user information in a text file that needs to be added in bulk
But there are requirements for formats
Format:
Pw_name:pw_passwd:pw_uid:pw_gid:pw_gecos:pw_dir:pw_shell
Its format is the same as the format of the/etc/passwd file

However, when finished newusers batch created users, there is no user template file in the generated home directory, these files need to be copied manually

Manual operation is cumbersome, so use scripts to execute:

  1. #!/bin/bash
  2. NewUsers $1 #该参数为用户文本文件的完整路径
  3. User_add = ' cat $1 | grep $i | cut-d:-f1 '
  4. For I in ' cat $1 | awk-f ': ' {print $6} ' #循环家目录
  5. Do
  6. If ' cat/etc/passwd | grep $i | Wc-l '! = 1
  7. echo "User Add Error, both or more User used same home directory! $i " #如果有两个家目录则报错
  8. Exit(1)
  9. Fi
  10. Cp-r/etc/skel $i
  11. Chown-r $user _add. $user _add $i
  12. Done

Second, batch change user password
By command CHPASSWD to achieve
Implementation method:

Cat Passwd.txt | CHPASSWD #直接实现修改密码

Where the Passwd.txt file format is as follows:
File format: User:password
User2:password2

Linux Bulk Add users and bulk change passwords

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.