1. Generate a random password (urandom version)
#!/bin/bash#author: Tintin (Jacob) #/dev/urandom file is a Linux built-in random device file #cat/dev/urandom can look inside the content, CTRL + C exit View # After viewing the contents of the file, Found content somewhat too random, including many special symbols, we need the password do not want to use these symbols #tr-dc ' _a-za-z0-9 ' </dev/urandom #该命令可以将随机文件中其他的字符删除, keep only uppercase and lowercase letters, numbers, underscores, But it's still too much. # we can continue to pass optimized content through the pipeline to the head command, showing only the first 10 bytes in a large amount of data # Note a preceded by an underscore tr-dc ' _a-za-z0-9 ' </dev/urandom | Head-c 10
2. Generate random password (string interception version)
#!/bin/bash#author: The Adventures of Tintin (Jacob) #设置变量key, all the possibilities of storing passwords (password vault), if additional characters are needed please add other password characters yourself # use $ #统计密码库的长度key = " 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "num=${#key} #设置初始密码为空pass = ' #循环8次, generate 8 for random password # Each time a random number of the length of the password library to take the remainder, to ensure that the extracted password characters do not exceed the length of the password vault # every time a random password is fetched, and the random password is appended to the pass variable last for i in {1..8}do index=$[random%num] pas s= $pass ${key: $index: 1}doneecho $pass
3. Generate random password (UUID version, 16 binary password)
#!/bin/bashuuidgen
4. generate random password (process ID version, digital password)
#!/bin/bashecho $$
This article is from the "Ding Ding Adventures" blog, please be sure to keep this source http://manual.blog.51cto.com/3300438/1969834
Shell script: Several possible ways to produce random passwords