歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> SHELL編程 >> Linux下利用shell腳本隨機生成密碼

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

日期:2017/3/1 9:21:17   编辑:SHELL編程

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

1,首先,安裝expect

yum install expect

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

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

mkpasswd -l 14 -s 2 -c 3 -C 3 -d 4

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

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

vi mkpasswd.sh

#!/bin/bash

i=1

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位

Copyright © Linux教程網 All Rights Reserved