Get the App
SLTechnology News&Howtos  ›  Development  › 

How to generate random passwords by Shell

Shulou Source: shulou.com Published: 2022-06-01 15:48:21 10月05日 Update

This article mainly introduces the relevant knowledge of "how to generate random passwords in Shell". The editor shows you the operation process through actual cases. The operation method is simple, fast and practical. I hope this article "how to generate random passwords in Shell" can help you solve the problem.

Generate random password (urandom version) #! / bin/bash # Author: Tintin Adventures (Jacob) # / dev/urandom file is a random device file built into Linux # cat / dev/urandom can see the contents, ctrl+c exits to view # after viewing the contents of the file, it is found that the content is a little too random, including a lot of special symbols The password we need does not want to use these symbols # tr-dc'_ A-Za-z0-9'# this command can delete other characters from the random file, leaving only uppercase and lowercase letters, numbers and underscores, but there is still too much content # We can continue to pipe the optimized content to the head command Show only the first 10 bytes in a large amount of data # Note An is preceded by an underscore tr-dc'_ A-Za-z0-9' to generate a random password (string truncated version) #! / bin/bash # Author: Tintin Adventure (Jacob) # sets the variable key to store all the possibilities of the password (password library) If you need other characters, please add other password characters # use $# to count the length of the password library key= "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" num=$ {# key} # set the initial password to empty pass='' # loop 8 times, generate 8 random passwords # each time is a random number to take the remainder of the length of the password base, make sure that the extracted password characters do not exceed the length of the password base # extract a random password each time The random password is appended to the last for i in {1.. 8} do index=$ [RANDOM%num] pass=$pass$ {key:$index:1} done echo $pass of the pass variable to generate a random password (UUID version, hexadecimal password) #! / bin/bash uuidgen 4. Generating random passwords (process ID version, digital passwords) #! / bin/bash echo $$about "how Shell generates random passwords" ends here. Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Password generation content character file version knowledge length underscore variable command number symbol industry Tintin loop different practical special possibility Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL NVidia vpn Shulou Information Linux