10 methods for generating random passwords using Linux
In general, it is confusing to generate passwords. If the complexity is insufficient, it will be insecure, it is too complex to press the keyboard to play the same character (but these characters are usually regular). You can also use the 1 password or keepass software to generate it, however, it seems that 1 password is charged. In this case, let's have fun using linux to generate random passwords;
A major advantage of Linux is that you can implement the same thing in hundreds of ways. For example, you can generate a random password in dozens of ways. This article describes ten methods to generate a random password.
1. Use the SHA algorithm to encrypt the date and output the first 32 characters:
- date +%s |sha256sum |base64 |head -c 32 ;echo
The result is as follows:
- ZTNiMGM0NDI5OGZjMWMxNDlhZmJmNGM4
2. Use embedded/dev/urandom and filter out characters that are not commonly used.. Here, only the first 32 characters of the output result are returned:
- < /dev/urandom tr -dc _A-Z-a-z-0-9 |head -c${1:-32};echo
The result is as follows:
- pDj0Xwz7exD_Qb5B27BwWsM1hrF3a7cJ
3. Use Random Functions of openssl
- openssl rand -base64 32
The result is as follows:
- rYJWqJlTLAYeX3j7nCbir20h1k/0CnqLNEuNyTScfKo=
4. This method is similar to the previous urandom.But it works reversely.
- tr -cd '[:alnum:]' < /dev/urandom | fold -w32 | head -n1;echo
The result is as follows:
- tpgudzF7sqtU4yyW2LVhmUQOZIQi87
5. Use the string commandWhich outputs printable strings from a file
- strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 32 | tr -d '\n'; echo
The result is as follows:
- W4v1iQtkmQ8sIDd9jxDQNpg8HPMOZ8
6. This is a simpler version of 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 a very useful dd command
- dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev
The result is as follows:
- 9+0RUd4U3HmSdMlgD7j0sf/r09MZFDVBS28W+pO2WcA
8. You can even generate a password that can be entered with only the left hand.
- </dev/urandom tr -dc '12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB' | head -c32; echo
The result is as follows:
- VTG3#TR4sAgXg3Z%##WZG4ZQ@GZ$wdqF
9. If you use the above method every time, it is better to save it as a function. If this is done, you can use randpw to generate a random password at any time after the command is run for the first time. Maybe youYou can save it to 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. The last method to generate a random password is the simplest.It can also run under Windows with Cygwin installed. It can also be run in Mac OS X. I am sure someone will complain that the password generated in this method is not random by other methods. But in fact, if you use all the strings it generates as the password, the password is random enough.
- date | md5sum
The result is as follows:
- e0d057b46a9a78346cbd94b25e574e79 -
- date | base64
The result is as follows:
- MjAxNOW5tCAwN+aciCAzMeaXpSDmmJ/mnJ/lm5sgMTc6MDA6MzYgQ1NUCg==
- ifconfig | md5sum
The result is as follows:
- 7c4243742aa515d45c12deca31428a95 -
You can even generate a nuclear bomb launch password. The following is an example of a growth password;
- ifconfig | base64
The result is as follows:
- ZW0xICAgICAgIExpbmsgZW5jYXA6RXRoZXJuZXQgIEhXYWRkciA3ODoyQjpDQjoyQjpCMDo5NCAg
- CiAgICAgICAgICBpbmV0IGFkZHI6MTkyLjE2OC4zLjUgIEJjYXN0OjE5Mi4xNjguMy4yNTUgIE1h
- c2s6MjU1LjI1NS4yNTUuMAogICAgICAgICAgaW5ldDYgYWRkcjogZmU4MDo6N2EyYjpjYmZmOmZl
- MmI6YjA5NC82NCBTY29wZTpMaW5rCiAgICAgICAgICBVUCBCUk9BRENBU1QgUlVOTklORyBNVUxU
- SUNBU1QgIE1UVToxNTAwICBNZXRyaWM6MQogICAgICAgICAgUlggcGFja2V0czoyMDY3NTY0IGVy
- cm9yczowIGRyb3BwZWQ6MCBvdmVycnVuczowIGZyYW1lOjAKICAgICAgICAgIFRYIHBhY2tldHM6
- ODg2NDUgZXJyb3JzOjAgZHJvcHBlZDowIG92ZXJydW5zOjAgY2FycmllcjowCiAgICAgICAgICBj
- b2xsaXNpb25zOjAgdHhxdWV1ZWxlb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