Shell create user and generate random password script share _linux shell

Source: Internet
Author: User

To create a random number method:

Copy Code code as follows:

1~~~~
/dev/urandom

In Linux, a device/dev/urandom is used to generate random sequence of numbers. Using this device we can generate random strings when needed.

For example, we're going to produce a 8-digit random combination of letters and numbers, so you can:

Copy Code code as follows:

[Linux@test/tmp]$ cat/dev/urandom | head-1 | md5sum | Head-c 8
6baf9282
2~~~~

In fact, Linux has already provided a system environment variable.
Copy Code code as follows:

[Chengmo@centos5 shell]$ Echo $RANDOM
66918
[Chengmo@centos5 shell]$ Echo $RANDOM
10092

There may be doubt, if more than 5 digits of random number how to get it?
10 digits, use% of 10
Copy Code code as follows:

echo $ ((random%10))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
VI passwd.sh
#创建一个 10-bit random password ...
#!/bin/bash
A= (a b c d e a B c D e F @ $% ^ 0 1 2 3 4 5 6 7 8 9)
For ((i=0;i<10;i++));d o
Echo-n ${a[$RANDOM% ${#a [@]}]}
Done
Echo

Execute script:
Copy Code code as follows:

[Root@2 shell]# SH passwd.sh
Bf8366c@13
VI useradd.sh
#创建5个账号, a random password is referenced.
#!/bin/bash
I=1
While [$i-le 5]
Todo
Useradd red$i
A= ' sh./passwd.sh '
echo "red$i: $a" >> sumuserpasswd
echo "~~~~~~~~~~~" >> sumuserpasswd
echo red$i: $a |chpasswd
# echo $a | Passwd–-stdin Red "$i"
Let i++
Done

Executive: SH useradd.sh
Copy Code code as follows:

[Root@2 shell]# Cat/etc/passwd|grep Red
Red1:x:515:515::/home/red1:/bin/bash
Red2:x:516:516::/home/red2:/bin/bash
Red3:x:517:517::/home/red3:/bin/bash
Red4:x:518:518::/home/red4:/bin/bash
Red5:x:519:519::/home/red5:/bin/bash
#查看结果
[Root@2 shell]# Cat SUMUSERPASSWD
Red1: $Ca 7%298d2
~~~~~~~~~~~~~
Red2:eeabbb7fb4
~~~~~~~~~~~~~
Red3:%3e385cece
~~~~~~~~~~~~~
red4:3@f% @B0584
~~~~~~~~~~~~~
Red5:adee^6bf$f
#测试一下
[Root@2 shell]# su red1
[Red1@2 shell]$ su red2
Password:
[Red2@2 shell]$

We can also use HTML to display our results:

HTML Table Code

Copy Code code as follows:

<body>
<tableborder= ' 1 ' >
<tr>
<td>user</td>
<td>passwd</td>
</tr>
<tr>
<td>test1</td>
<td>123123</td>
</tr>
<tr>
<td>test2</td>
<td>aaabbb</td>
</tr>
</table>
</body>

You can guide your account and password to the Web page in HTML syntax.
Copy Code code as follows:

Temp=index.html
echo "echo "<tableborder=\" 1\ ">" >> $TEMP
echo "<tr><td>username</td><td>password</td></tr>>> $TEMP
echo "<tr><td> $i </td><td> $a </td></tr>" >> $TEMP
echo "</table></body>echo "Open index.html"

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.