8 Ways to Create a Random Password in a Linux Shell

Having a strong password for authentication in the service by username and password is very important. Sometimes you need to protect your account or server and try to keep your data safe. It is often said that a strong password should contain at least 14 characters with variations such as your lowercase / uppercase letters and letters. In most cases, a long password is considered more secure than a short one because it is difficult to obtain. In this tutorial, we will see many ways to create a strong password from the Linux command line. We’ll look at various ways to create a more reliable and reasonably secure password using the Linux command line. You need to generate a stronger password from the command line so that it has various methods and utilities that are already available. We will discuss many of the methods, and you can choose any of the ways to create a password according to your needs.

Password Generation with OpenSSL

On Linux, there are several methods for creating and generating passwords for the Linux command line. The first thing we are trying to use is OpenSSL. The following are the steps that must be completed for this purpose.

Step 1: First of all, open the terminal by clicking on Ubuntu Launcher and find the terminal.

Linux terminal search

Step 2: Now click on Terminal and wait for the terminal to open.

Open Terminal

8 Ways to Create a Random Password in a Linux Shell

Step 3: After opening the terminal you will have the following screen:

Linux Terminal is ready to use

Step 4:

The command that is used to create a stronger password includes the OpenSSL rand function. This will help us generate 14 random characters per line. Command “openssl rand –base64 14 ”.

Create random password with OpenSSL

The result will be a strong 14-character password, as shown below.

Password created using OpenSSL

The second command we use to generate the password filters out / dev / urandom with tr. This will allow us to remove all unnecessary characters, and then only print the first 14 characters.

Create password using urandom device

The output of the above command is as follows:

random password

The output allowed us to print the first 14 characters only by deleting all unnecessary ones.

To use pwgen, we need to install this tool first. This tool will help us generate random but meaningless passwords. Although the passwords generated by him are random, they can still be pronounced. So, now we will install the tool using the following command.

install pwgen

Enter your credentials as requested

enter password

Installation will eventually begin. The command line will look the same as on the screen below.

PWGEN is installed

After the installation is complete, we will generate a random string containing 14 characters.

Use pwgen to create a password

The line we got at random is this.


Gpg can also be used to create a strong password of 14 characters. The gpg tool uses the following command to generate 14 characters.

Using gpg to create a random password

The result of this command is

gpg result

And finally, we have a generated password.


In this method we will use SHA, we can also hash the date. It goes through base64. As a result, we get output as the top of 32 characters.

Use sha to create a password

Here is the result of 32 characters and a strong password to ensure system security.

Password received

Password generation is quite simple using the command line. Although this is not accidental, it is still useful if we use the entire password. The simplest command for this purpose is as follows:

password string created using md5sum

The result of the above command is a string as shown below.

Password md5sum

And this command is very simple and simple enough to remember.

APG is an automatic password generator, it is already installed on all Ubuntu systems. It is also an easy to use utility. This helps us generate various passwords that are random input.

To generate the entire random passwords, we can run apg -a 1, which will give us passwords with 8-10 random characters. To do this, we used the apg –a 1 command. We will run and see the various passwords generated in the output.

random apg password

The output has many random passwords.

List of created passwords

Password generation using makepasswd

makepasswd”Also can be used to generate passwords. To use this utility, we first install it. We will use the command sudo apt-get install makepasswd.

Install makepasswd

Enter the required credentials.

Enter admin password

After entering the credentials, installation will begin.

Install makepasswd

Press Y to continue

Once the utility is installed, we will write a command that makepasswd –count NumberOfPasswords –minchars MinLengthOfPassword,

First, we report how many passwords we want to generate and what the length of each password should be. Here we asked to generate 4 passwords with a length of eight for each of them.

Using makepasswd

The result is shown below. In total, we have 4 passwords of 8 characters each.

List of created passwords

The team is responsible for generating a list of random passwords based on the number of passwords that we want to generate, and their length is also determined by us.


In this tutorial, we discussed many ways to generate passwords from the Linux command line. There are many methods that already exist. Few of the utilities are already present on the Linux command line, while for those that cannot be easily installed using the available commands. In this tutorial, we discussed the openssh, urandom, pwegn, gpg, sha, date, apg, and makepasswd utilities. All of these commands guarantee the creation of a stronger password from the Linux command line and are useful for the user to ensure the security of their systems.

8 Ways to Create a Random Password in a Linux Shell