Linux Combat quiz: Create users and passwords in bulk-see if you can

Source: Internet
Author: User
Tags stdin

Linux Combat quiz: Create users and passwords in bulk-see if you can?


The old boy education of the first Combat exam: Batch Create 10 user Stu01-stu10, and set a random 8-bit password, require not to use the shell loop (for example: For,while, etc.), can only be implemented with Linux commands and pipelines.


Method 1:

# echo Stu{01..10}|tr "" \ n "|sed-r ' s# (. *) #useradd \1; pass=$ ((random+10000000)); echo "$pass" |passwd--stdin \1; Echo-e "\1 \ t ' echo" $pass "'" >>/tmp/oldboy.log#g ' |bash

# Cat/tmp/oldboy.log


The above command is actually a combination of the following commands to spell N, to give a command stu01 the user's process is disassembled as follows:

Useradd stu01;

pass=$ ((random+10000000));

echo "$pass" |passwd--stdin stu01;

Echo-e "Stu01 ' echo" $pass "'" >>/tmp/oldboy.log

Special Note: If the shell loop structure is simpler, the purpose of restricting the use of loops is to exercise the students ' Basic command application

Ability to learn that we haven't learned the shell cycle course yet.


Method 2:

# Echo stu{11..12}|xargs-n1 useradd; Echo stu{11..12}: ' Cat/dev/urandom|tr-dc 0-9|fold-w8|head-1 ' |xargs-n1|t Ee-a pass.txt|chpasswd

Method 3:

There is a wrong argument, cut should take the second field should be-F2 results should be: # echo stu{21..30} | Tr ' \ n ' | Sed-e ' S/^/useradd/'-E ' s/\ (stu[0-9]\{2\}\) $/\1 \&\& echo "\ 1: ' Echo $[$RANDOM **3] | Cut-c1-8 ' "| Tee-a UserInfo.txt | Cut-d:-f2 | passwd--stdin \1/' | Bash

Function: Create 10 users is stu21-stu30 its password is random number variables randomly generated, are saved to UserInfo.txt, format: username:passwd This write is not good if there is better must share Oh! The above random number I used to generate a date, is not correct, because there may be a repetition, so I then simply use Random**3 to take its top 8, to ensure that uniqueness


Method 4:

# Echo stu{01..10} |tr ' \ n ' |sed-rn ' [email protected]^ (. *) [email protected] \1; echo $RANDOM |md5sum|cut-c 1-8 >/data/\1;cat/data/\1|passwd--stdin \[email protected] ' |bash

This problem can not be achieved on their own students are orders based on the lack of clearance, need to add sufficient horsepower.


Linux Combat quiz: Create users and passwords in bulk-see if you can

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.