Top Ad unit 728 × 90

10 Ways to Generate a Random Password from the Command Line


An awesome aspect concerning Linux is that you can do likewise many diverse ways—actually something as basic as producing an irregular watchword can be fulfilled with many distinctive charges. Here's 10 ways you can do it. 

We assembled these summons from Command-Line Fu and tried them out all alone Linux PC to verify they work. You ought to have the capacity to use at any rate some of these on Windows with Cygwin introduced, however we didn't test every one of them—the last one unquestionably meets expectations however 

[post_ad]

Generate a Random Password

For any of these arbitrary secret word charges, you can either alter them to yield an alternate watchword length, or you can simply utilize the first x characters of the created watchword on the off chance that you don't need such a long secret key. Ideally you're utilizing a secret word supervisor like LastPassanyway so you don't have to remember them. 

This strategy utilizes SHA to hash the date, goes through base64, and afterward yields the main 32 characters.
date +%s | sha256sum | base64 | head -c 32 ; echo
This method used the built-in /dev/urandom feature, and filters out only characters that you would normally use in a password. Then it outputs the top 32.
< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;
This one uses openssl’s rand function, which may not be installed on your system. Good thing there’s lots of other examples, right?
openssl rand -base64 32
This one works a lot like the other urandom one, but just does the work in reverse. Bash is very powerful!
tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1
Here’s another example that filters using the strings command, which outputs printable strings from a file, which in this case is the urandom feature.
strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n'; echo
Here’s an even simpler version of the urandom one.
< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6
This one manages to 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
You can even create a random left-hand password, which would let you type your password with one hand.
</dev/urandom tr -dc '12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB' | head -c8; echo ""
If you’re going to be using this all the time, it’s probably a better idea to put it into a function. In this case, once you run the command once, you’ll be able to use randpw anytime you want to generate a random password. You’d probably want to put this into your ~/.bashrc file.
randpw(){ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;}
You can use this same syntax to make any of these into a function—just replace everything inside the { }
And here’s the easiest way to make a password from the command line, which works in Linux, Windows with Cygwin, and probably Mac OS X. I’m sure that some people will complain that it’s not as random as some of the other options, but honestly, it’s random enough if you’re going to be using the whole thing.
date | md5sum

[post_ad] 
10 Ways to Generate a Random Password from the Command Line Reviewed by Vijitashv on 3:51 pm Rating: 5

No comments:

Powered By Blogger, Share by Star Tuan

Biểu mẫu liên hệ

Name

Email *

Message *

Powered by Blogger.