Home > Hosting > Server

What are the methods of generating random passwords in Linux

2023-02-15 13:51:03

This article mainly explains the methods of generating random passwords in Linux. What are the password methods!

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 result is as follows:

ztnimgm0ndi5ogzjmwmxndlhzmjmngm4

2. Use the embedded /dev/urandom , and filter out those characters that are not used very much every day. Here, only the first 32 characters of the result are output:

< /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 the random function of openssl

openssl rand -base64 32

The generated results are as follows:

ryjwqjltlayex3j7ncbir20h1k/0cnqlneunytscfko=

4. This method is similar to urandom before, but it works in reverse

tr -cd '[:alnum:]' < /dev/urandom | fold -w32 | head -n1 ;echo

The result is as follows:

tpgudzf7sqtu4yyw2lvhmuqoziqi87

5. Using the string command, it outputs from a file Printable strings

strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 32 | tr -d 'n'; echo< /p>

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 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 typed with only the left hand

The generated results are as follows:

vtg3#tr4sagxg3z%##wzg4zq@gz$wdqf

9. If every If you use one of the above methods every time, it is better 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 only randpw. Maybe you can save it in your ~/.bashrc file

randpw(){ < /dev/urandom tr -dc _a-z-a-z-0-9 | head -c$ {1:-16};echo;}

The result is as follows:

vgbx8cno950riykzrppya4bvbavzby_x

10. Finally this This method of generating random passwords is the easiest. It can also run under windows with cygwin installed. on mac oIt can also be run under s x. I'm sure there will be complaints that this method generates passwords that are not as random as other methods. But in fact, if you use all the strings it generates as a password, then this password is random enough

date | md5sum

The generated results are as follows:

e0d057b46a9a78346cbd94b25e574e79 -
date | base64

The generated results are as follows:

mjaxnow5tcawn+acicazmeaxpsdmmj/mnj /lm5sgmtc6mda6mzygq1nucg==
ifconfig | md5sum

The generated results are as follows:

7c4243742aa515d45c12deca31428a95 -

Even if you want to generate a The password for nuclear bomb launch can be used. The following is an example of generating a long password;

ifconfig | base64

The generated results are as follows:

zw0xicagicagiexpbmsgzw5jyxa6rxrozxjuzxqgiehxywrkcia3odoyqjpdqjoyqjpcmdo5ncag
ciagicagicagicbpbmv0igfkzhi6mtkylje2oc4zljugiejjyxn0oje5mi4xnjgumy4yntugie1h
c2s6mju1lji1ns4yntuumaogicagicagicagaw5lddygywrkcjogzmu4mdo6n2eyyjpjymzmomzl
mmi6yja5nc82ncbty29wztpmaw5rciagicagicagicbvucbcuk9brenbu1qgulvotklorybnvuxu
sunbu1qgie1uvtoxntawicbnzxryawm6mqogicagicagicagulggcgfja2v0czoymdy3nty0igvy
cm9yczowigryb3bwzwq6mcbvdmvycnvuczowigzyyw1lojakicagicagicagifryihbhy2tldhm6
odg2ndugzxjyb3jzojagzhjvchblzdowig92zxjydw5zojagy2fycmllcjowciagicagicagicbj
b2xsaxnpb25zojagdhhxdwv1zwxlbjoxmdawiaogicagicagicagulggynl0zxm6mjazndkzntex
icgxotqumcbnauipicbuwcbiexrlczozmjuynzuxniaomzeumcbnauipcgpsbyagicagicagtglu
ayblbmnhcdpmb2nhbcbmb29wymfjayagciagicagicagicbpbmv0igfkzhi6mti3ljaumc4xicbn
yxnroji1ns4wljaumaogicagicagicagaw5lddygywrkcjogojoxlzeyocbty29wztpib3n0ciag
icagicagicbvucbmt09qqkfdsybsvu5osu5hicbnvfu6mty0mzygie1ldhjpyzoxciagicagicag
icbswcbwywnrzxrzoju2otkzmsblcnjvcnm6mcbkcm9wcgvkojagb3zlcnj1bnm6mcbmcmftztow
ciagicagicagicbuwcbwywnrzxrzoju2otkzmsblcnjvcnm6mcbkcm9wcgvkojagb3zlcnj1bnm6
mcbjyxjyawvyojakicagicagicagignvbgxpc2lvbnm6mcb0ehf1zxvlbgvuojagciagicagicag
icbswcbiexrlczozmzezmdcxosaomzeunsbnauipicbuwcbiexrlczozmzezmdcxosaomzeunsbn
auipcgo=

Thank you for reading. The above is the content of the methods of generating random passwords in Linux. After studying this article, I believe that everyone has the problem of what methods of generating random passwords in Linux. For a deeper understanding, the specific usage needs to be verified by everyone in practice. This is Yisu Cloud, the editor will push more articles about relevant knowledge points for you, welcome to pay attention!


Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us