Linux Tech Hacks

Your Linux tech hacks and Tips

10 Command Line Tricks To Create A Random Password


10 Command Line Tricks To Create A Random Password

Here's time to have some fun with command lines and and create a password that no one can hack (hopefully)!


One amazing part about Linux is that it allows you to do one thing in hundreds of different ways, even if it is something as simple as generating a random password. Here's 10 ways you can do it.

All of these random password commands can be modified to achieve a different password length, or simply use the first x characters of the generated password if you don't want such a long password. We suggest you to use password managers like LastPass so that you don't need to memorize them.

1. This method uses SHA to hash the date, runs through base64, and then outputs the top 32 characters.

date +%s | sha256sum | base64 | head -c 32 ; echo
2. 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;
3. This one uses openssl's rand function, in case this is not installed on your system don't worry, we have a lots of other examples!

openssl rand -base64 32
4. This one works a lot like the other urandom one, but just does the work in reverse. Bash is indeed super powerful!

tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1
5. This example 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
6. An even simpler version of the urandom one.

< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6
7. 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
8. 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 ""




9. 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 { }
10. 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. And yes, that's much more easy to remember.
date | md5sum
Courtesy: howtogeek


 Fonte: 10 Command Line Tricks To Create A Random Password

Comente com o Facebook:

Nenhum comentário:

Postar um comentário

Siga-nos