在Linux系统中,生成随机密码可以通过多种方法实现

steps

1.openssl生成密码
[root@mvp ~]# openssl rand -base 14Usage: rand [options] num
where options are
-out file - write to file
-engine e - use engine e, possibly a hardware device.
-rand file:file:... - seed PRNG from files
-base64 - base64 encode output
-hex - hex encode output

openssl rand -base64 8
openssl rand -hex 3 -out pass.txt --6位

2.使用urandom 生成高强度密码
使用tr条件来过滤/dev/urandom 的输出,从而删掉那些不想要的字符,并打印出第一个出现的14位字符

< /dev/urandom tr -dc A-Za-z0-9 | head -c14; echo
< /dev/urandom tr -dc A-Za-z0-9 | head -c6;echo

3.设置快捷命令
vim /etc/bashrc
genpasswd() {
< /dev/urandom tr -dc '[:alnum:]' | head -c6;echo
}