Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to generate random passwords by Shell

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report