北京SEO

linux中shell生成随机密码示例

2019/10/10/17:47:06  阅读:1802  来源:谷歌SEO算法  标签: 自媒体

shell命令可以生成随机密码我在很早以前就介绍过一些例子了,这里看到一站长写的文章再整理一下与大家一起学习他的方法.

为了生成更加无序及相应复杂的密码,因此写了个生成随机密码的脚本,在此之前生成密码通常我是通过如下命令实现的:

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

好了,不说所了,直接上脚本,代码如下:

  1. [root@liufofushell]#catmake_random_passwd.sh
  2. #!/bin/bash
  3. #########################################
  4. #authorwww.phpfensi.com
  5. #emailphpfensi.com@qq.com
  6. #date2014-08-15
  7. #########descprition##################
  8. #1.生成随机密码
  9. #2.
  10. ########################################
  11. #initvariables
  12. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  13. exportPATH
  14. ff_outputdir=/tmp/liufofu
  15. curdate=$(date+%Y%m%d)
  16. curtime=$(date+%H%M%S)
  17. ff_logfile=${ff_outputdir}/${curdate}.log
  18. if[!-e${ff_outputdir}];then
  19. mkdir-p${ff_outputdir}
  20. fi
  21. #处理过程中产生的日志由日志函数来进行处理记录
  22. [root@liufofushell]#catmake_random_passwd.sh
  23. #!/bin/bash
  24. #########################################
  25. #authorwww.phpfensi.com
  26. #emailphpfensi@qq.com
  27. #date2014-08-15
  28. #########descprition##################
  29. #1.生成随机密码
  30. #2.
  31. ########################################
  32. #initvariables
  33. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  34. exportPATH
  35. ff_outputdir=/tmp/liufofu
  36. curdate=$(date+%Y%m%d)
  37. curtime=$(date+%H%M%S)
  38. ff_logfile=${ff_outputdir}/${curdate}.log
  39. if[!-e${ff_outputdir}];then
  40. mkdir-p${ff_outputdir}
  41. fi
  42. #处理过程中产生的日志由日志函数来进行处理记录
  43. functionlog()
  44. {
  45. echo"`date+"%Y:%m:%d%H-%M-%S"`$1">>${ff_logfile}
  46. }
  47. rpasswd=""
  48. if[-z$1];then
  49. rlen=16
  50. else
  51. rlen=$1
  52. fi
  53. ary=(0123456789\(abcdefghii\)jklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@%\#\!)
  54. for((i=1;i<=${rlen};i++));do
  55. rpasswd=${rpasswd}${ary[$RANDOM%${#ary[*]}]}
  56. #echo-n${ary[$RANDOM%${#ary[*]}]}
  57. done
  58. echo${rpasswd}

在这个脚本中,你可以自行定义ary这个数组,生成你自己所要的密码类型.

脚本的运行效果如下:

  1. [root@liufofushell]#shmake_random_passwd.sh
  2. z%J7Jy7EE@YrWi8E
  3. [root@liufofushell]#shmake_random_passwd.sh10
  4. lW6IiCcJyi
  5. [root@liufofushell]#shmake_random_passwd.sh6
  6. ZiEIqj
  7. [root@liufofushell]#shmake_random_passwd.sh1
  8. Z
  9. [root@liufofushell]#shmake_random_passwd.sh7
  10. Jyw28dB
  11. [root@liufofushell]#shmake_random_passwd.sh
  12. 39eZkiTrp1e1kDb%
  13. [root@liufofushell]#shmake_random_passwd.sh
  14. #Aw%Jn@PPcO9bH)r

广告内容

linux中shell生成随机密码示例 linux中shell生成随机密码示例 linux中shell生成随机密码示例

相关阅读

热门评论

互联网十八般武艺 互联网十八般武艺

互联网十八般武艺

总篇数179

精选文章

RMAN中catalog和nocatalog区别介绍 小技巧:为Linux下的文件分配多个权限 zimbra8.5.1安装第三方签名ssl证书的步骤 解决mysql不能远程连接数据库方法 windows服务器mysql增量备份批处理数据库 mysql中slow query log慢日志查询分析 JavaScript跨域问题总结 Linux下负载均衡软件LVS配置(VS/DR)教程 mysql中权限参数说明 MYSQL(错误1053)无法正常启动

SEO最新算法