To generate a more unordered and complex password, write a script that generates a random password, which is usually done by using the following command
Cat/dev/urandom | Head-n 1 | md5sum | Head-c 16
All right, no, no, just go straight to the script.
The code is as follows |
Copy Code |
[Root@liufofu shell]# Cat make_random_passwd.sh #!/bin/bash ######################################### # author Www.111cn.net # email 14158286@qq.com # date 2014-08-15 ######### descprition ################## # 1. Generate Random passwords # 2. ######################################## #init variables Path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin Export PATH
Ff_outputdir=/tmp/liufofu curdate=$ (Date +%y%m%d) curtime=$ (Date +%h%m%s) Ff_logfile=${ff_outputdir}/${curdate}.log
if [!-e ${ff_outputdir}];then Mkdir-p ${ff_outputdir} Fi
#处理过程中产生的日志由日志函数来进行处理记录 [Root@liufofu shell]# Cat make_random_passwd.sh #!/bin/bash ######################################### # author Www.111cn.net # email 14158286@qq.com # date 2014-08-15 ######### descprition ################## # 1. Generate Random passwords # 2. ######################################## #init variables Path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin Export PATH
Ff_outputdir=/tmp/liufofu curdate=$ (Date +%y%m%d) curtime=$ (Date +%h%m%s) Ff_logfile=${ff_outputdir}/${curdate}.log
if [!-e ${ff_outputdir}];then Mkdir-p ${ff_outputdir} Fi
#处理过程中产生的日志由日志函数来进行处理记录 function log () { echo "' Date +"%y:%m:%d%h-%m-%s "$" >> ${ff_logfile} } Rpasswd= "" If [-Z $];then Rlen=16 Else Rlen=$1 Fi ary= (0 1 2 3 4 5 6 7 8 9\ (a b c d e F g h i i\) J k l m n o p q R S t u v w x y z a b c d e F g h i j k l m n o P Q R S T U V W X Y Z @%\#\!) For ((i=1;i<=${rlen};i++));d o rpasswd=${rpasswd}${ary[$RANDOM% ${#ary [*]}]} #echo-N ${ary[$RANDOM% ${#ary [*]}]} Done Echo ${RPASSWD} |
In this script, you can define your own ary this array and generate the type of password you want.
The script works as follows:
code is as follows |
copy code |
[Root@liufofu shell]# sh make_random_passwd.sh z%j7jy7ee@yrwi8e [root@liufofu shell]# sh make_random_passwd.sh ten Lw6iiccjyi [Root@liufofu shell]# sh make_random_passwd.sh 6 zieiqj [root@liufofu shell]# sh make_random_ passwd.sh 1 Z [root@liufofu shell]# sh make_random_passwd.sh 7 jyw28db [root@liufofu shell]# sh Make_rando m_passwd.sh 39ezkitrp1e1kdb% [root@liufofu shell]# sh make_random_passwd.sh #Aw%jn@ppco9bh) r |