10 ways to generate random passwords on the Linux command line

Source: Internet
Author: User
Tags install openssl openssl

One of the great advantages of the Linux operating system is that you can use up to hundreds of ways to implement it for the same thing. For example, you can generate random passwords in dozens of ways. This article describes 10 ways to generate a random password.
These methods are collected in command-line Fu and tested on our own Linux PC. Some of these 10 methods can also be run under Windows with Cygwin installed, especially the last method.

Generate a random password

For either of the following methods, you can either generate a password of a specific length with a simple modification, or use only the first n bits of its output. Hopefully you're using some sort of lastpass-like password manager so you don't have to remember these randomly generated passwords yourself.

1. This method uses the SHA algorithm to encrypt the date and output the first 32 characters of the result:

1  ; Echo

2. This method uses embedded/dev/urandom and filters out characters that are not used everyday. This also outputs only the first 32 characters of the result:

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

3. This method uses the random function of OpenSSL. If your system may not have OpenSSL installed, you can try any of the other nine methods or install OpenSSL yourself.

1  +


4. This method is similar to the previous urandom, but it works in reverse. Bash's features are very powerful!

1 ' [: alnum:] ' </dev/urandom | fold-w30 | Head-n1


5. This method uses the string command, which prints a printable string from a file:

1  ' [[: Alnum:]] '  - ' \ n '; Echo

6. This is a simpler version of using Urandom:

1 </dev/urandom tr-dc _a-z-a-z-0-9 | Head-c6

7. This method uses a very useful DD command:

1  if=/dev/urandom bs=1 count=2>/dev/null02-| Rev

8. You can even generate a password that can be entered with only the left hand:

1  ' [Email PROTECTED]#$%QWERTQWERTASDFGASDFGZXCVBZXCVB ' ""

9. If one of the above methods is used each time, the better way is to save it as a function. If you do, you can use RANDPW at any time to generate a random password after you run the command for the first time. Maybe you can save it in your ~/.BASHRC file.

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

10. Finally, this method of generating random passwords is the simplest. It can also run under Windows with Cygwin installed. May also run under Mac OS X. I'm sure there will be complaints that this method generates a password that has no other method to be random. But actually if you use all the strings that it generates as passwords, the password is random enough.

1 Date | Md5sum

Yes, this method is also extremely good to remember.


Original link: Lowell heddings translation: Geek Van-the trail is empty

Link: http://www.geekfan.net/7064/

10 ways to generate random passwords on the Linux command line

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.