Linux下利用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位

本文永久更新链接地址

相关内容