1、使用/dev/urandom + tr + head实现取随机字符

    随机纯数字(20位为例):

    1. cat /dev/urandom | tr -dc 0-9 | head -c 20

    随机小写字母 + 数字(20位为例):

    1. cat /dev/urandom | tr -dc a-z0-9 | head -c 20

    随机大小写字母 + 数字(20位为例):

    1. head /dev/urandom | tr -dc A-Za-z0-9 | head -c 20

    随机168位字符

    1. head -n 80 /dev/urandom | tr -dc A-Za-z0-9 | head -c 168
    2. head /dev/urandom | od |head -c 168 | tr -d " "

    随机10位数字

    1. head /dev/urandom | cksum|cut -d" " -f1

    2、通过系统环境变量($RANDOM)实现

    1. echo $RANDOM | md5sum | cut -c 5-11

    3、通过openssl产生随机数

    1. openssl rand -base64 30
    2. openssl rand -hex 66

    4、通过时间data产生随机数

    1. date +%s-%N

    5、通过UUID生成产生随机数

    1. cat /proc/sys/kernel/random/uuid

    6、使用expect附带的mkpasswd生成随机数

    1. yum install expect -y
    2. expect_mkpasswd -l 15 -d 3 -C 5 -s 1

    小结:

    • expect_mkpasswd - -h查看帮助

    • -l 指定密码长度

    • -d 指定密码中数字的数量

    • -c 指定密码中小写字母的数量

    • -C 指定密码中大写字母的数量

    • -s 指定密码中特殊字符的数量