Solve the Problem of batch adding a large number of accounts in Linux

Source: Internet
Author: User
Tags format definition email account
Article Title: solves the problem of batch adding a large number of accounts in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
   Method 1:
The most common task for a system administrator is to manage user accounts, including adding and reducing users, configuring hard disk quotas, and enabling the personal homepage, in the early stage of system construction, it is often a waste of time to answer some user information related to adduser (useradd) when a large number of users need to be added, and no relevant records are left, it often makes system managers suffer, let alone subsequent management actions.
Pdadduser can solve this problem by quickly and conveniently creating a large number of user accounts as needed. The user's password can be composed of random or specified methods, the account, UID, and home directory can be set by the system administrator and can be used with related commands. This feature is highly elastic and has relevant records, which can greatly reduce the burden on managers. In this paper, the author will use a simple example to illustrate the use of Linux and FreeBSD these two sets of systems, more detailed description can refer to the http://ghs.ssd.k12.wa.us /~ Pdavis /.
  
   Install
The latest version of pdadduser is 1.2, but some systems cannot be executed in version 1.2, so use version 1.1 instead.
  
1.1 Linux Installation
Step 1. tar xvfz pdadduser-1.2.tar.gz unzip Pdadduser Software
Step 2. Switch the cd pdadduser-1.2 into the pdadduser-1.2 directory
Step 3. make users edit pdadduser
Step 4. gcc pause. c? O pause resume sometimes has problems with this file, so edit it.
When the two executable files pdadduser and pause are generated.
  
1.2 install FreeBSD
Step 1. tar xvfz pdadduser-1.1.tar.gz unzip Pdadduser Software
Step 2. Switch the cd pdadduser-1.1 into the pdadduser-1.2 directory
Step 3. gcc? Wall? I--I. pdadduser? O pdadduser users edit pdadduser
Step 4. gcc pause. c? O pause edit pause
When the two executable files pdadduser and pause are generated.
  
2 Command Format
The complete Instruction format of pdadduser is as follows. I will only describe it briefly in this article. For more details, refer to the unlocked README.
Pdadduser-n [-f] [-F] [-o] [-h home-directory-format>] [-g] [-r] [-p] [-t] [-d]-c 'command1' ['command2'...]
Option description:
-N: The text file in the user list, which is required. For example, the file content is as follows:
Peter Davis
Joe Schmoe
Jane Doe
-F: Format of the combination of user names. The format is defined as follows:
$ N: the nth word (the start WORD is $0). If it does not exist, ignore it.
% X. n: the nth character in the nth word. If not, ignore
For example, '% 0.0 $ 1' is a combination of 0th characters and 0th characters in 1st words (the same is true by default ), therefore, the user names obtained from the preceding example are 'pdavis ', 'jschmoe', and 'jdoe '; '% 3.0 $ 1' is a combination of 0th characters and 3rd characters in 1st words. Therefore, the user names obtained in the preceding example are 'edav' and 'schmoe', respectively ', 'edoe '.
-F: The combination format of the user's full name. The format definition is the same as-f, for example, '$0 $ 1' is a combination of 0th characters and 1st characters (the same is true by default). Therefore, the full names of users obtained in the preceding example are 'Peter wands', respectively ', "Joe Schmoe ', 'Jane Doe'; and '% 0.0. $1 'gets 'p. davis ', 'J. schmoe ', 'J. doe '.
-O: output files, including user names, passwords, and error messages. Be sure to place them in a safe place. Of course, if this file exists, the system administrator should be able to play some tricks. If the output file is '-', it is output only from the screen. We do not recommend this file. In addition, the error message is '! 2 !! 235! 'And so on. See the following example to remind managers.
-H: the format of the user's home directory. First, define the following special characters:
U: User Name
G: User Group
F: full user name
The format of the user's home directory is defined as follows:
$: Entire word
% N: the nth character in the word
For example, '/home/$ g/$ U' is'/home/users/pdavis '. Assume that the user name is 's9351033 ', if you want the home directory to be '/home/users/S/93/S9351033', the format should be '/home/users/% 0u/% 1u % 2u/$ U '. The default format is '/home/$ U '.
-G: user group.
-R: UID range. The default value is 500 to 1000.
-P: The default value is a random number generated by the system. Of course, you can also customize it. For example, % xr is a random number that generates r characters. The default value is 6 characters.
-T: The test mode does not actually add users.
-D: In the debugging mode, you can view the execution process of each command.
-C 'command1' ['command2'...]: This is the most important part of pdadduser. That is, pdadduser provides relevant parameters for COMMAND execution. A detailed example is provided below. The parameters are as follows:
$ U: User Name
$ P: User Password
$ I: User UID
$ G: User Group
$ F: full user name
$ D: user's home directory
  
3. Execute
After learning about the command parameters, we can use pdadduser to add new users. However, since Linux and FreeBSD are slightly different, I will explain them separately.
  
3.1 Linux
First, create a text file for the user list. The example is as follows: named userlists. In addition, the author also creates a shell executable file named pda4linux.
. /Pdadduser-n $1-o $2-g users-d-c '/usr/sbin/adduser-c "$ f"-u $ I-g $ g-d $ d $ u'' (printf "$ p ";. /pause 1; printf "$ p") |/usr/bin/passwd $ u; ''mkdir $ d/public_html ''cp index.html. samp $ d/public_html/index.html ''chown-R $ u. $ g $ d/public_html ''chmod 755 $ d' edquota-p shie $ U'
In pda4linux, the execution File '/usr/sbin/adduser-c "$ f"-u $ I-g $ g-d $ U' adds users, '(printf "$ p ";. /pause 1; printf "$ p") |/usr/bin/passwd $ u; 'Change User Password, 'mkdir $ d/public_html' cp index.html. samp $ d/public_html/index.html ''chown-R $ u. $ g $ d/public_html ''chmod 755 $ d'. Create a personal homepage and copy the Quota template of 'edquota-p shie $ U.
Of course, pda4linuxis to be modified before it can be used to your system, such as index.html. samp, shie, and so on. The execution format is as follows:
./Pda4linux user list output file
For example:
./Pda4linux userlists accounts
Run the following command to view the output file accounts in pda4linux for the first time:
Peter Davis: name = pdavis passwd = aacuug group = users uid = 500 homedir =/home/pdavis
Joe Schmoe: name = jschmoe passwd = ogyjwm group = users uid = 501 homedir =/home/jschmoe
Jane Doe: name = jdoe passwd = appymj group = users uid = 502 homedir =/home/jdoe
After performing the merge operation, observe the output file accounts as follows:
Peter Davis: name = pdavis passwd = aacuug group = users uid = 500 homedir =/home/pdavis
Joe Schmoe: name = jschmoe passwd = ogyjwm group = users uid = 501 homedir =/home/jschmoe
Jane Doe: name = jdoe passwd = appymj group = users uid = 502 homedir =/home/jdoe
! 1 !! 256! Peter Davis: name = pdavis passwd = dedrnm group = users uid = 503 homedir =/home/pdavis
! 1 !! 256! Joe Schmoe: name = jschmoe passwd = hfyhoy group = users uid = 503 homedir =/home/jschmoe
! 1 !! 256! Jane Doe: name = jdoe passwd = ueixrd group = users uid = 503 homedir =/home/jdoe
It can be seen that there will be problems when new users are added at this time, and the problems are repeated, and sometimes there will be problems when the passwords are too simple to generate, once again, please be sure to place this file in a safe place.
  
   Method 2,
   Automatically create an account-a rescue for primary and secondary school network administrators (1)
A: Environment: RedHat Linux + cle
1. Capture the file first! [Click Here] (http://netlab.kh.edu.tw/download/account creation tool. Zip)
2. Enter linux with root permission
3. Put the unlocked files in a new/work directory.
4. cd/work [go to the work Directory]
5. chmod 700 * [change all script file attributes to-rwx ------]
6. Modify the description in/etc/profile
PATH = "$ PATH:/usr/X11R6/bin" changed
PATH = "$ PATH:/usr/X11R6/bin:/usr/sbin"
After saving the disk and leaving the system, log on again as root.
7. #./cmenu execute script? N
8. Select [1] to automatically create an account
9. Select [3] to generate a school account
10. rules you need: for example, the English letter: stu, the lowest grade: 1, the highest grade: 6, the number of classes in each first grade: 9, the number of students in each class: 50, then, an account will be created based on the rule of group + grade + class + seat number. However, no password is available and no email can be sent or received. Please go back to the main menu and continue.
11. Select [4] batch change user password in the main menu (2)
12. Enter the group name: stu. For other operations, follow the instructions to generate a pwtemp? N, the content is the user account and group + four-digit password.
(Reference: RedHat Linux is ready for use upon installation. Lai AFU. Gao jianzhi, Song gang)
  
   Automatically create an account-the administrator of the Primary and Secondary School has helped (2)
A: Next we will explain how to automatically generate an account notice.
1. Copy the generated pwtemp file to Win98 or WinNT.
2. Use the Excel or Access import function to import data into a data table and enter fields such as number, name, account, and password.
3. Go back to Word to open a new file.
4. Use the tool-> merge and print
5. The simple format is as follows:> and other fields that represent Merging
Kaohsiung City and Peace country email account allocation notice
User name:> distribution Date:
E-mail:> @ mail.hpps.kh.edu.tw
Server Information:
Internal mail → POP3: mail.hpps.kh.edu.tw
External mail → SMTP: mail.hpps.kh.edu.tw
Internal mail server account:> password:>
  
6. A new file will be generated after the merge. You can check whether the result is correct.
Related Article

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.