参考51CTO博客作者long9617的原创作品
https://blog.51cto.com/longlei
1、$RANDOM
[root@fan ~]# echo $RANDOM
28679
[root@fan ~]# echo $RANDOM
6675
[root@fan ~]# echo $RANDOM
177
获取8位随机字符和数字
[root@fan ~]# echo $RANDOM |md5sum |cut -c 1-8
f890d6d1
[root@fan ~]# echo $RANDOM |cksum |cut -c 1-8
30180605
2、openssl
openssl rand 用于产生指定长度个bytes的随机字符
-base64 / -hex 对随机字符串进行base64编码或用hex格式显示
[root@fan ~]# openssl rand -base64 5
zBGxHQs=
[root@fan ~]# openssl rand -base64 4
h3T2OQ==
[root@fan ~]# openssl rand -base64 8
hRD42l4L2bQ=
[root@fan ~]# openssl rand -base64 10
azR7c+a6JR/vmg==
[root@fan ~]# openssl rand -base64 10
IxlqRmi0P70E/g==
获取随机字符
[root@fan ~]# openssl rand -base64 6
fb7cqvab
[root@fan ~]# openssl rand -base64 9
9sUSeGKEoEFD
获取8位随机数字
[root@fan ~]# openssl rand -base64 8 |cksum |cut -c 1-8
86343899
3、date
[root@fan ~]# date +%s%N
1563045292290688359
[root@fan ~]# date +%s
1563045298
[root@fan ~]# date +%N
294467639
[root@fan ~]# date +%N |cut -c 1-8
76014224
4、/dev/urandom
[root@fan ~]# head /dev/urandom | cksum
1981767266 3484
5、计算机生成的uuid码产生随机字符
[root@fan ~]# cat /proc/sys/kernel/random/uuid
2acc0f46-a09c-4f3f-be77-2fce60ba5cde
[root@fan ~]# cat /proc/sys/kernel/random/uuid |cut -c 1-8
d852b731
6、安装软件expect,然后使用命令mkpasswd生成随机字符
[root@localhost ~]# yum -y install expect
[root@localhost ~]# mkpasswd -l 8
6cvHu1P_
[root@localhost ~]# mkpasswd -l 8
g7jR3!Lt
[root@localhost ~]# mkpasswd -l 8
Y9wCwk4-
[root@localhost ~]# mkpasswd
h8{o4wVWf
[root@localhost ~]# mkpasswd
9bnI&zD4u
[root@localhost ~]# mkpasswd|md5sum
d9fabd642a8d4e260c95604bdd7d9cea -
[root@localhost ~]# mkpasswd|md5sum
c5ddd81803a9308bcf31999c2441c5d9 -
7、产生随机密码
[root@fan ~]# pwgen -1
lei3aeTh
[root@fan ~]# pwgen 5 -1
tu7eH
[root@fan ~]# pwgen 12 -1
lu5aeNae0eel
[root@fan ~]# pwgen 20 -1
zoh2mah2neu9neYeihok
网友评论