# 1、example ```bash cat /dev/urandom | head -1 | md5sum | head -c 6 # 随机纯数字(20位为例): head /dev/urandom | tr -dc 0-9 | head -c 20 # 随机小写字母+数字(20位为例): head /dev/urandom | tr -dc a-z0-9 | head -c 20 # 随机大小写字母+数字(20位为例): head /dev/urandom | tr -dc A-Za-z0-9 | head -c 20 # 3rd_session head -n 80 /dev/urandom | tr -dc A-Za-z0-9 | head -c 22 cat /dev/urandom | od -x | tr -d ' ' | head -n 1 ``` # 2、熵 ```bash # 查看系统熵池的容量 cat /proc/sys/kernel/random/poolsize # 查看系统熵池中拥有的熵数 cat /proc/sys/kernel/random/entropy_avail # 查看从熵池中读取熵的阀值,当 entropy_avail 中的值少于这个阀值,这读取 /dev/random 会被阻塞 cat /proc/sys/kernel/random/read_wakeup_threshold # tomcat启动慢 if [[ "$JAVA_OPTS" != *-Djava.security.egd=* ]]; then JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/./urandom" fi JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/./urandom" ``` # 3、参考 * [Myths about /dev/urandom](https://www.2uo.de/myths-about-urandom/) * [How To Safely Generate A Random Number](https://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/) * [在虚拟机上使用hasged作为熵源是否合适](https://security.stackexchange.com/questions/34523/is-it-appropriate-to-use-haveged-as-a-source-of-entropy-on-virtual-machines) * [使用Haveged为云服务器设置熵](https://www.digitalocean.com/community/tutorials/how-to-setup-additional-entropy-for-cloud-servers-using-haveged)