There are times when a random password is to be generated during developing applications. Like you are creating database, you need to set a strong password for users. You are creating an admin user in any application, then also a strong password is to be generated.
A good question here is what is meant by a strong password. Here are the characteristics of a secure password
- Minimum length of password should be 8 characters. More is better.
- Password should be a combination of alphabets, numbers and special characters ($#!, etc.)
- It should have both lowercase and uppercase alphabets.
There are many different ways to generate a random password but I’ll go through one of the best ways that will fulfill the characteristics of strong password.
pwgen is an automatic password generator. This tool is not available by default on Linux distributions. So, we will install it.
sudo apt-get install pwgen pwgen -h Usage: pwgen [ OPTIONS ] [ pw_length ] [ num_pw ] Options supported by pwgen: -c or --capitalize Include at least one capital letter in the password -A or --no-capitalize Don't include capital letters in the password -n or --numerals Include at least one number in the password -0 or --no-numerals Don't include numbers in the password -y or --symbols Include at least one special symbol in the password -r <chars> or --remove-chars=<chars> Remove characters from the set of characters to generate passwords -s or --secure Generate completely random passwords -B or --ambiguous Don't include ambiguous characters in the password -h or --help Print a help message -H or --sha1=path/to/file[#seed] Use sha1 hash of given file as a (not so) random generator -C Print the generated passwords in columns -1 Don't print the generated passwords in columns -v or --no-vowels Do not use any vowels so as to avoid accidental nasty words
Let’s generate a random strong password using pwgen.
pwgen -c -n -y 16 1
Re-run this command to generate new password combinations until you feel good with one 🙂
So, guys give this a try in generating your next password.
Have a good day!