Home >Operation and Maintenance >Linux Operation and Maintenance >What are the methods for generating random passwords in Linux?
1. Use the sha algorithm to encrypt the date and output the first 32 characters of the result:
date %s |sha256sum |base64 |head -c 32 ;echo
The generated results are as follows:
ztnimgm0ndi5ogzjmwmxndlhzmjmngm4
2. Use the embedded /dev/urandom and filter out those characters that are not commonly used in daily life . Only the first 32 characters of the result are output here:
< /dev/urandom tr -dc _a-z-a-z-0-9 |head -c${1:-32};echo
The generated results are as follows:
pdj0xwz7exd_qb5b27bwwsm1hrf3a7cj
3. Use openssl’s random function
openssl rand - base64 32
The generated result is as follows:
ryjwqjltlayex3j7ncbir20h1k/0cnqlneunytscfko=
4. This method is similar to the previous urandom, but it It works in reverse
tr -cd '[:alnum:]' < /dev/urandom | fold -w32 | head -n1;echo
generated The result is as follows:
tpgudzf7sqtu4yyw2lvhmuqoziqi87
5. Use the string command, which outputs a printable string from a file
strings / dev/urandom | grep -o '[[:alnum:]]' | head -n 32 | tr -d '\n'; echo
The generated results are as follows:
w4v1iqtkmq8sidd9jxdqnpg8hpmoz8
6. This is a simpler version using urandom
< /dev/urandom tr -dc _a-z-a-z-0-9 | head -c32;echo
The generated result is as follows:
rmdlgspn_bm-izvfwz9bei0rf-jiy6gs
7. Use the very useful dd command
dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev
The generated results are as follows:
9 0rud4u3hmsdmlgd7j0sf/r09mzfdvbs28w po2wca
8. You can even generate a password that can be entered with only your left hand
The generated results are as follows:
vtg3 #tr4sagxg3z%##wzg4zq@gz$wdqf
9. If you use one of the above methods every time, a better way is to save it as a function. If you do this, you can generate random passwords at any time after running the command for the first time using just randpw. Maybe you can save it to your ~/.bashrc file
randpw(){ < /dev/urandom tr -dc _a-z-a-z-0-9 | head -c${ 1:-16};echo;}
The generated results are as follows:
vgbx8cno950riykzrppya4bvbavzby_x
10. The last way to generate random passwords The method is the simplest. It can also be run under windows with cygwin installed. It can also run under mac os x. I'm sure there will be complaints that the passwords generated this way are less random than other methods. But in fact if you use all the strings it generates as the password, then the password is random enough
#date | md5sum
The generated result is as follows:
e0d057b46a9a78346cbd94b25e574e79 -
date | base64
The generated results are as follows:
##mjaxnow5tcawn acicazmeaxpsdmmj/mnj/lm5sgmtc6mda6mzygq1nucg==ifconfig | md5sum
The generated results are as follows:
7c4243742aa515d45c12deca31428a95 -You can even generate a nuclear bomb launch password. The following is an example of generating a long password; ifconfig | base64The generated results are as follows:##zw0xicagicagiexpbmsgzw5jyxa6rxrozxjuzxqgiehxywrkcia3odoyqjpdqjoyqjpcmdo5ncag
ciagicagicagicbpbmv0igfkzhi6mtkylje2oc4zljugiejjyxn 0oje5mi4xnjgumy4yntugie1hc2s6mju1lji1ns4yntuumaogicagicagicagaw5lddygywrkcjogzmu4mdo6n2eyyjpjymzmomzl
mmi6yja5nc82ncbty29wztpmaw5rciagicagicagicbvucbcuk9brenbu1qgulvotklorybnvuxu
sunbu1qgie1uvtoxntawicbnzxryawm6mqogicagicagicagulggcgfja2v0czoymdy3nty0igvy
cm9yczowigryb3bwzwq6mcbvdmvycnvuczowigzyyw1lojakicagicagicagifryihbhy2tldhm6
odg2ndugzxjyb3jzojagzhjvchblzdowig92zxjydw5zojagy2fycmllcjowciagicagicagicbj
b2xsaxnpb25zojagdhhx dwv1zwxlbjoxmdawiagicagicagulggynl0zxm6mjazndkzntex
icgxotqumcbnauipicbuwcbiexrlczozmjuynzuxniaomzeumcbnauipcgpsbyagicagicagtglu
ayblbmnhcdpmb2nhbcbmb29wymfjayagciagicagicagicbpbmv0igfkzhi6m ti3ljaumc4xicbn
yxnroji1ns4wljaumaogicagicagicagaw5lddygywrkcjogojoxlzeyocbty29wztpib3n0ciag
icagicagicbvucbmt09qqkfdsybsvu5osu5hicbnvfu6mty0mzygie1ldhjpyzoxciagicagicag
icbswcbwywnrz xrzoju2otkzmsblcnjvcnm6mcbkcm9wcgvkojagb3zlcnj1bnm6mcbmcmftztow
ciagicagicagicbuwcbwywnrzxrzoju2otkzmsblcnjvcnm6mcbkcm9wcgvkojagb3zlcnj1bnm6
mcbjyxjyawvyojakicag icagicagignvbgxpc2lvbnm6mcb0ehf1zxvlbgvuojagciagicagicag
icbswcbiexrlczozmzezmdcxosaomzeunsbnauipicbuwcbiexrlczozmzezmdcxosaomzeunsbn
auipcgo=
The above is the detailed content of What are the methods for generating random passwords in Linux?. For more information, please follow other related articles on the PHP Chinese website!