In our modern digital realm, securing your digital assets with a confidential code, commonly referred to as a ‘password‘, has become an essential practice.
However, it’s evident that the era of weak and easily guessable passwords is long gone. Yet, do you find yourself caught in the hassle of endless brainstorming sessions, all in an effort to meet the ever-expanding criteria for creating a strong password that hackers won’t crack?
To confront this issue, Linux offers various command-line password generators utilized to automatically craft secure passwords. Among these tools, the “makepasswd” command stands out as a commonly utilized command.
This guide will cover the process of installing makepasswd to generate random encrypted password hashes using various levels of complexity in Linux.
Install makepasswd in Linux
The makepasswd command uses “dev/urandom” to generate random passwords that prioritize security over pronounceability. This command also offers the ability to encrypt plaintext passwords. Additionally, the user can also specify the length as well as the number of passwords they want to obtain.
To install makepasswd on a Linux system, you can use the package manager specific to your distribution as shown.
$ sudo apt install makepasswd [On Debian, Ubuntu and Mint] $ sudo yum install makepasswd [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a sys-apps/makepasswd [On Gentoo Linux] $ sudo apk add makepasswd [On Alpine Linux] $ sudo pacman -S makepasswd [On Arch Linux] $ sudo zypper install makepasswd [On OpenSUSE]
Once you have successfully installed “makepasswd” on your system, it is essential to familiarize yourself with its syntax and usage.
$ makepasswd [option...]
In the above syntax, the ‘option‘ also known as the flag, is used to change the conduct of the command. To see the brief introduction along with the options this command offers, you can type.
$ makepasswd --help
How to Generate a Secure 10-Character Password
To generate a random password with a length of 10 characters and outputs it to the terminal, use the following command which will generate a password that consists of a mixture of uppercase letters, lowercase letters, digits, and special characters, making it suitable for various security needs.
$ makepasswd --chars=10 L7waUwnRGL
How to Save Generate Password to File
You might be thinking about making a record of the passwords that are being generated by your Linux terminal. One way is to manually note down the complex passwords on a piece of paper!!! However, Linux saves you from this fuss by providing you the opportunity to save the generated passwords in a file on your system.
You can achieve this by using the right-angle brackets '>>'
followed by the file’s name to redirect the password into that file as shown below:
$ makepasswd --chars=10 >> output.txt
Upon successful execution of the above command, the generated password will be appended to the “output.txt” file, which can be verified using the cat command, as demonstrated below.
$ cat output.txt YbQ8sbgGaU
How to Generate Passwords with Lowercase Letters
Passwords having only lowercase letters are considered to be safer than those having only numerals or uppercase alphabets.
To limit the password generation to the defined character set, you can make use of the '--string'
flag, which constraint the command to utilize only the characters enclosed within single quotation marks, as shown in the example below:
$ makepasswd --chars=13 --string='abcdefghijklmnopqrstuvwxyz' vvimkbgxouvdl
This command will generate a password of 13 characters containing only lowercase alphabets.
How to Encrypt Passwords with MD5 Digest Algorithm
In this example, let’s explore how the “makepasswd” command empowers users to combine multiple flags for tailoring password creation to their specific requirements.
Note: The MD5 algorithm (which stands for Message Digest Algorithm 5) is a cryptographic hash function utilized to produce a hash value of 128 bits (16 bytes).
For example, by running the following command, you can effortlessly generate multiple passwords, each consisting of 12 characters and encrypted using the MD5 hash algorithm:
$ makepasswd --count=5 --crypt-md5 --maxchars=12
Here’s what each part of the command means:
--count
to specify the number of passwords to be generated.--crypt-md5
denotes that the generated passwords will be encrypted using the MD5 hash algorithm for enhanced security.--maxchars
determines the length of each password.
You have successfully obtained 5 passwords, each consisting of a maximum of 12 characters, encrypted by the MD5 hash algorithm.
How to Generate Encrypted Passwords with Specific Seeds
While generating passwords, the aim is to produce secure combinations. However, in some cases, you might require a predictable password for specific testing purposes. In such cases, the '--randomseed'
option can prove useful. However, it is suggested not to create passwords, using this flag, that are required to be secure.
Let’s try to craft some insecure passwords for testing purposes. To achieve this, we’ll employ the '--minchars'
flag to determine the minimum number of characters in each password along with the seed “12345” for randomness, as demonstrated below:
$ makepasswd --count=5 --minchars=8 --randomseed=12345
How to Generate Passwords with Specific Characters
Incorporating special characters into passwords is a good practice to enhance their strength and complexity. To introduce specific special characters into your password, you can employ the ‘–string’ flag, as demonstrated earlier.
$ makepasswd --count=3 --maxchars=15 --string='aeiouAEIOU_0123456789!@#$%^&*()'
The above command will create 3 passwords, each with a maximum length of 15 characters, incorporating a combination of the characters mentioned within the single quotation marks.
How to Encrypt Passwords Using a Crypt Salt of 512
The makepasswd gifts us an option of “cryptsalt” which adds random data to a password before hashing. This increases its safety by adding a secondary layer of security to it.
To create two passwords using the crypt algorithm with a salt length of 512 bits with a minimum length of 6 characters, use:
$ makepasswd --count=2 --crypt --cryptsalt=512 --minchars=6
Conclusion
In today’s digital world, safeguarding personal information from cyber intrusions is a paramount concern for computer users. To fulfill this objective, passwords play a crucial role.
This guide offers an in-depth look into the ‘makepasswd‘ command in Linux, a tool that facilitates the creation of robust passwords. Additionally, we’ve delved into various examples to illustrate the practical application of this valuable command.