linux下利用shell腳本隨機生成密碼

1,首先,安裝expectgit

yum install expectshell


生成方式,咱們介紹二種,一是命令行方式,二是shell腳本方式。bash

(1)命令行生成隨機密碼
ide


 mkpasswd -l 14 -s 2 -c 3 -C 3 -d 4命令行

生成一個14位的密碼,至少包含2個特殊字符,3個小寫字母,3個大寫字母和4個數字。ci


(2)編寫shell腳本,批量生成30個密碼it

vi mkpasswd.shclass


#!/bin/bash密碼


i=1im

echo "########kim by 51cto.com##########" >/tmp/passwd.txt

while [ $i -le 30 ];do

/usr/bin/mkpasswd -l 14 -s 2 -c 3 -C 3 -d 4 >>/tmp/passwd.txt

let i+=1

done

exit;


(3)mkpasswd參數詳解

-l #      (length of password, default = 7)

 

                  指定密碼的長度,默認是7位數

 

-d #      (min # of digits, default = 2)

 

                  指定密碼中數字最少位數,默認是2位

 

-c #      (min # of lowercase chars, default = 2)

 

                  指定密碼中小寫字母最少位數,默認是2位

 

-C #      (min # of uppercase chars, default = 2)

 

                  指定密碼中大寫字母最少位數,默認是2位

 

-s #      (min # of special chars, default = 1)

 

                  指定密碼中特殊字符最少位數,默認是1位

相關文章
相關標籤/搜索