為了產生更加無序及相應複雜的密碼,因此寫了個產生隨機密碼的指令碼,在此之前產生密碼通常我是通過如下命令實現的
cat /dev/urandom | head -n 1 | md5sum | head -c 16
好了,不說所了,直接上指令碼
代碼如下 |
複製代碼 |
[root@liufofu shell]# cat make_random_passwd.sh #!/bin/bash ######################################### # author www.111cn.net # email 14158286@qq.com # date 2014-08-15 ######### descprition ################## # 1.產生隨機密碼 # 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.產生隨機密碼 # 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"` $1 " >> ${ff_logfile} } rpasswd="" if [ -z $1 ];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++));do rpasswd=${rpasswd}${ary[$RANDOM % ${#ary[*]}]} #echo -n ${ary[$RANDOM % ${#ary[*]}]} done echo ${rpasswd}
|
在這個指令碼中,你可以自行定義ary這個數組,產生你自己所要的密碼類型。
指令碼的運行效果如下:
代碼如下 |
複製代碼 |
[root@liufofu shell]# sh make_random_passwd.sh z%J7Jy7EE@YrWi8E [root@liufofu shell]# sh make_random_passwd.sh 10 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_random_passwd.sh 39eZkiTrp1e1kDb% [root@liufofu shell]# sh make_random_passwd.sh #Aw%Jn@PPcO9bH)r |