本文共 3041 字,大约阅读时间需要 10 分钟。
Linux操作系统的一大优点是对于同样一件事情,你可以使用高达数百种方法来实现它。例如,你可以通过数十种方法来生成随机密码。本文将介绍生成随机密码的十种方法。
date +%s |sha256sum |base64 |head -c 32 ;echo
生成结果如下:ZTNiMGM0NDI5OGZjMWMxNDlhZmJmNGM4
< /dev/urandom tr -dc _A-Z-a-z-0-9 |head -c${1:-32};echo
生成结果如下:pDj0Xwz7exD_Qb5B27BwWsM1hrF3a7cJ
openssl rand -base64 32
生成结果如下:rYJWqJlTLAYeX3j7nCbir20h1k/0CnqLNEuNyTScfKo=
tr -cd '[:alnum:]' < /dev/urandom | fold -w32 | head -n1;echo
生成结果如下:tpgudzF7sqtU4yyW2LVhmUQOZIQi87
strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 32 | tr -d '\n'; echo
生成结果如下:W4v1iQtkmQ8sIDd9jxDQNpg8HPMOZ8
< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32;echo
生成结果如下:rMDlGSPN_bm-IZVFWz9BEi0rF-jIy6gs
dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev
生成结果如下:9+0RUd4U3HmSdMlgD7j0sf/r09MZFDVBS28W+pO2WcA
</dev/urandom tr -dc '12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB' | head -c32; echo
生成结果如下:VTG3#TR4sAgXg3Z%##WZG4ZQ@GZ$wdqF
randpw(){ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;}
生成结果如下:vgBX8cNo950RiykZRpPYa4BvbAvZbY_x
date | md5sum
生成结果如下:e0d057b46a9a78346cbd94b25e574e79 -
date | base64
生成结果如下: MjAxNOW5tCAwN+aciCAzMeaXpSDmmJ/mnJ/lm5sgMTc6MDA6MzYgQ1NUCg== ifconfig | md5sum 生成结果如下:7c4243742aa515d45c12deca31428a95 -
甚至你想生成一个核弹发射密码都可以,下面是一个生成长密码的例子;
ifconfig | base64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gICAgIGNvbGxpc2lvbnM6MCB0eHF1ZXVlbGVuOjAgCiAgICAgICAg ICBSWCBieXRlczozMzEzMDcxOSAoMzEuNSBNaUIpICBUWCBieXRlczozMzEzMDcxOSAoMzEuNSBN aUIpCgo=本文转自奔跑在路上博客51CTO博客,原文链接http://blog.51cto.com/qiangsh/2061051如需转载请自行联系原作者
qianghong000