How to create multiple users in Linux

Source: Internet
Author: User
How to create multiple users in Linux

@! /Bin/sh (definition uses sh shell)
Groupadd users (create a user group)
@ T_class code (define the first parameter as the code of the total group and assign the variable "t_class ")
T_class = $1
@ Class code (defines the second parameter as the group code and assigns the variable "num_class ")
Num_class = 'expr $2 + 0'
If (test $ num_class-le 9) (The following Code ensures that the number of digits in the grouping code is two digits)
Then
Num_class = "0" $ num_class
Fi
@ Max user ID (define the third parameter as the maximum ID of the group user and assign the variable "max_stid ")
Max_stid = 'expr $3 + 0'
@ Init user ID (the user ID of this group starts from 1)
Num_userid = 1
@ Mkdir User Home (create a public directory named "FST" for all users in the "/home" Directory)
If [! -X/home/Fst]
Then
Mkdir/home/Fst
Fi
If [! -X/home/Fst/$1 $ num_class] (create a directory named after the group code for each group under the common directory of the Group)
Then
Mkdir/home/Fst/$1 $ num_class
Fi
While (test $ num_userid-Le $ max_stid) (starts from user ID 1 until the maximum ID)
Do
If (test $ num_userid-le 9) (The following ensures that the number of digits in the user code is two digits)
Then
Num_userid = "0" $ num_userid
Fi
User_name = $ t_class $ num_class $ num_userid (the username is merged into three code groups: Total group, group, and user ID, and the user_name variable is assigned)
@ Save User passwd to file user_pwlist (append the "user_pwlist" file row by row in the format of "Name: passwd" for initializing the user password)
Echo $ user_name ":" $ user_name> user_pwlist
@ Add user (create the user and assign the "users" group to create the user directory)
Adduser-G users-D/home/Fst/$1 $ num_class/$ user_name
@ Set quota (set the quota for this user. The maximum capacity is 20 mb and there is no limit on the number of files)
Setquota-U $ user_name 10240 20480 0 0/home
@ Set Directory mode (set the permission of the user directory to 755)
Chmod 755/home/Fst/$1 $ num_class/$ user_name
@ Current user ID add one (add 1 to the user ID, prepare for the next cycle, and create the next user)
Num_userid = 'expr $ num_userid + 1'
Done
Chpasswd <user_pwlist (the following two actions are used to set passwords for all users just created)
Pwconv
Rm user_pwlist-F (delete the "user_pwlist" file)

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.