终端随机生成密码命令和随机生成密码脚本

释放双眼,带上耳机,听听看~!

终端随机生成密码

1. 生成随机密码命令1 (推荐, Mac 和 Linux可用)


1
2
1[root@localhost ~]# openssl rand -base64 32
2
  1. 生成随机密码命令2 (Linux可用)

1
2
1[root@localhost ~]# </dev/urandom tr -dc '12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB' | head -c8; echo ""
2

*(简单)(Linux可用) 根据 head -c8 8来选择长度

以下是根据这个命令各种变体


1
2
3
4
5
6
7
8
1[root@localhost ~]# < /dev/urandom tr -dc '!@#$%_A-Z-a-z-0-9' | head -c8; echo ""
2
3[root@localhost ~]# < /dev/urandom tr -dc '_A-Z-a-z-0-9' | head -c8; echo ""
4
5[root@localhost ~]# < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6
6
7[root@localhost ~]# < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;
8
  1. 生成随机密码命令3 (Linux可用)

1
2
1[root@localhost ~]# dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev
2
  1. 生成随机密码命令4 (Linux可用)

1
2
1[root@localhost ~]# date +%s | sha256sum | base64 | head -c 32 ; echo
2

32 – 是控制长度

  1. 生成随机密码命令5 (Linux可用)

1
2
1[root@localhost ~]# tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1
2
  1. 生成随机密码命令6 (Linux可用)

1
2
1[root@localhost ~]#strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n'; echo
2

生成随机密码脚本 (Mac 和 Linux 可用)

 [root@localhost ~]# cat passwd.sh


1
2
3
4
5
6
7
8
9
10
1#!/bin/bash
2
3a=(a b c d e A B C D E F @ $ % ^  0 1 2 3 4 5 6 7 8 9)
4
5for ((i=0;i<20;i++));do
6    echo -n ${a[$RANDOM % ${#a[@]}]}
7done
8
9echo
10

[root@localhost ~]# chmod +x passwd.sh 

[root@localhost ~]# sh passwd.sh 

2bFeBC84e9D^7$A$6%a^

给TA打赏
共{{data.count}}人
人已打赏
安全运维

设计模式之访问者模式

2021-12-12 17:36:11

安全运维

OpenSSH-8.8p1离线升级修复安全漏洞

2022-1-9 9:47:55

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索