国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

linux中shell生成隨機密碼示例

2024-08-27 23:58:38
字體:
來源:轉載
供稿:網友

shell命令可以生成隨機密碼我在很早以前就介紹過一些例子了,這里看到一站長寫的文章再整理一下與大家一起學習他的方法.

為了生成更加無序及相應復雜的密碼,因此寫了個生成隨機密碼的腳本,在此之前生成密碼通常我是通過如下命令實現的:

cat /dev/urandom | head -n 1 | md5sum | head -c 16

好了,不說所了,直接上腳本,代碼如下:

  1. [root@liufofu shell]# cat make_random_passwd.sh  
  2. #!/bin/bash 
  3. ######################################### 
  4. # author        m.survivalescaperooms.com 
  5. # email         Vevb.com@qq.com 
  6. date          2014-08-15 
  7. ######### descprition ################## 
  8. # 1.生成隨機密碼 
  9. # 2. 
  10. ######################################## 
  11. #init variables 
  12. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin 
  13. export PATH 
  14.  
  15. ff_outputdir=/tmp/liufofu 
  16. curdate=$(date +%Y%m%d) 
  17. curtime=$(date +%H%M%S) 
  18. ff_logfile=${ff_outputdir}/${curdate}.log 
  19.  
  20. if [ ! -e ${ff_outputdir} ];then 
  21.     mkdir -p ${ff_outputdir} 
  22. fi 
  23.  
  24. #處理過程中產生的日志由日志函數來進行處理記錄 
  25. [root@liufofu shell]# cat make_random_passwd.sh  
  26. #!/bin/bash 
  27. ######################################### 
  28. # author        m.survivalescaperooms.com 
  29. # email         Vevb@qq.com 
  30. date          2014-08-15 
  31. ######### descprition ################## 
  32. # 1.生成隨機密碼 
  33. # 2. 
  34. ######################################## 
  35. #init variables 
  36. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin 
  37. export PATH 
  38.  
  39. ff_outputdir=/tmp/liufofu 
  40. curdate=$(date +%Y%m%d) 
  41. curtime=$(date +%H%M%S) 
  42. ff_logfile=${ff_outputdir}/${curdate}.log 
  43.  
  44. if [ ! -e ${ff_outputdir} ];then 
  45.     mkdir -p ${ff_outputdir} 
  46. fi 
  47.  
  48. #處理過程中產生的日志由日志函數來進行處理記錄 
  49. function log() 
  50.     echo "`date +"%Y:%m:%d %H-%M-%S"` $1 "  >> ${ff_logfile} 
  51. rpasswd="" 
  52. if [ -z $1 ];then 
  53.     rlen=16 
  54. else 
  55.     rlen=$1 
  56. fi 
  57. 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 @ % \# \!) 
  58. for ((i=1;i<=${rlen};i++));do 
  59.     rpasswd=${rpasswd}${ary[$RANDOM % ${#ary[*]}]} 
  60.     #echo -n ${ary[$RANDOM % ${#ary[*]}]} 
  61. done 
  62. echo ${rpasswd} 

在這個腳本中,你可以自行定義ary這個數組,生成你自己所要的密碼類型.

腳本的運行效果如下:

  1. [root@liufofu shell]# sh make_random_passwd.sh 
  2. z%J7Jy7EE@YrWi8E 
  3. [root@liufofu shell]# sh make_random_passwd.sh 10 
  4. lW6IiCcJyi 
  5. [root@liufofu shell]# sh make_random_passwd.sh 6 
  6. ZiEIqj 
  7. [root@liufofu shell]# sh make_random_passwd.sh 1 
  8. [root@liufofu shell]# sh make_random_passwd.sh 7 
  9. Jyw28dB 
  10. [root@liufofu shell]# sh make_random_passwd.sh 
  11. 39eZkiTrp1e1kDb% 
  12. [root@liufofu shell]# sh make_random_passwd.sh 
  13. #Aw%Jn@PPcO9bH)r

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 策勒县| 佛坪县| 土默特左旗| 准格尔旗| 博兴县| 蓬溪县| 理塘县| 巴林左旗| 弋阳县| 会东县| 祁阳县| 桃园市| 河北区| 青龙| 千阳县| 九龙坡区| 遵化市| 湖口县| 灵寿县| 阳谷县| 平舆县| 明星| 阜宁县| 仁化县| 漾濞| 永吉县| 花垣县| 韶关市| 溧水县| 施秉县| 韶山市| 江安县| 和龙市| 建昌县| 呼图壁县| 太白县| 华亭县| 库伦旗| 鄱阳县| 衡南县| 临沭县|