修改服务器root密码脚本,借助配置管理工具可以批量执行。随机生成32为的包含数字,大小写字母及特殊字符的root密码,干掉弱口令。[1]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#!/bin/bash special[0]="#" special[1]="$" special[2]="&" special[3]="^" special[4]="!" special[5]="%" special[6]="@" randstr(){ index=0 str="" for i in {a..z}; do arr[index]=$i; index=`expr ${index} + 1`; done for i in {A..Z}; do arr[index]=$i; index=`expr ${index} + 1`; done for i in {0..9}; do arr[index]=$i; index=`expr ${index} + 1`; done for i in ${special[@]}; do arr[index]=$i; index=`expr ${index} + 1`; done for i in {1..32}; do ((random=$RANDOM%$index)) str="$str${arr[random]}" done echo $str } password=`randstr` #echo $password echo "$password" |passwd root --stdin |
另外可以用命令生成随机字符串,但是速度较慢
1、生成随机数
echo $RANDOM2、生成随机字符串
cat /dev/urandom | strings -n C | head -n L
cat /dev/urandom | sed 's/[^a-zA-Z0-9]//g' | strings -n C | head -n L前者生成全字符的随机字符串,后者生成数字加字母的随机字符串。其中C表示字符串的字符数,L表示要生成多少行字符。[2]
参考资料
1 2 |
[1]. http://www.cnblogs.com/sheldonxu/archive/2012/11/24/2785491.html [2]. http://blog.163.com/163_zhujingwei/blog/static/97330597201121611431502/ |
发表回复