Simple Ways to Generate a Random Password on Linux Shell

User Avatar
πŸ‘€ admin
πŸ”΄ Admin
✍️ The most important thing in the world is to not be alone.
⏳ Last active: 15 Apr 2025 at 16:01
πŸ“… Created: 19 Mar 2022 at 11:42
πŸ‘€ Viewed: 36 times
βœ‰οΈ Send Email

Image

Having a strong password when authenticating to a service by username and password is very important. Sometimes, you need to protect your account or server, and try to keep your data safe and secure. It is often said that a strong password must have a minimum of 14 characters with variations like you may have lowercases/uppercases in the characters and alphabets. Mostly the long password is considered to be much more secure than a short one since it is hard to get. In this tutorial, we will see many ways to generate a strong password from Linux command line. We will have a look at many different means to create a stronger password that is secure enough, using the Linux command line. You need to generate a stronger password from the command line so, it has various different methods and utilities that are already available. We will be discussing many of the methods and you may choose any of the ways for generation of a password as per your need.

Generation of a password with OpenSSL

Several methods, exist in Linux to create and generate the passwords for Linux command line. The first one we are trying is by using OpenSSL. Following are the steps that need to be followed for this purpose.

Step 1: First of all, open Terminal by clicking on Ubuntu launcher and search for Terminal.

Image

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

Image

Step 3: Once the terminal is opened, you will have a screen like this:

Image

Step 4:

The command that is used to generate a stronger password includes OpenSSL rand function. This will help us generate 14 random characters in a string. The command is β€œopenssl rand –base64 14”.

Image

The outcome will be a strong password of 14 characters as shown below.

Image

Generation of a password using urandom

The second command which we are using to generate a password has filtered /dev/urandom output with tr. This will allow us to delete all of the unwanted characters and then help us to print the first 14 characters only.

Image

The output of the above command is as follows:

Image

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

Generation of a password using pwgen

For using pwgen we need to install this tool at first. This tool will help us generate some random yet meaningless passwords. Although the passwords generated by it are random still are pronounceable. So, we will now install the tool using the following command.

Image

Enter the credentials as asked

Image

The installation will eventually begin. The command line will look just like the screen below.

Image

Once the installation has been done, we will generate a random string having 14 characters in it.

Image

The string we got randomly is this one.

Image

Generation of a password using gpg

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

Image

The outcome of this command is

Image

And in the end, we have a password generated which is.

Image

Generation of a password using SHA

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

Image

Here is the outcome containing the 32 characters yet a strong password to keep the system safe.

Image

Generation of a password via an easy way

The generation of a password is quite easy using the command line. Although it is not random still it is useful if we utilize the whole password. The easiest command for this purpose is as follows:

Image

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

Image

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

Generation of a password using apg

APG is Automatic Password Generator, it is already installed on all Ubuntu systems. It is also an easily used utility. It helps us generate various passwords that are the random input.

In order to generate entire random passwords, we can run apg -a 1, which will give us the passwords with 8-10 random characters. The command we used for this purpose is apg –a 1. We will run and see various passwords generated in the output.

Image

The output has many random passwords.

Image

Generation of a password using makepasswd

β€œmakepasswd” can also be used to generate passwords. For using this utility, we install it at first. We will use the command sudo apt-get install makepasswd.

Image

Enter the required credentials.

Image

On writing the credentials, the installation will begin.

Image

Press Y to continue

Once the utility has been installed, we will write the command which is makepasswd –count NumberOfPasswords –minchars MinLengthOfPassword.

At first, we tell how many passwords we are aiming to generate and what must be the length of each of the password. Here we have asked to generate 4 passwords with length as eight for each of it.

Image

The outcome is shown below. We have a total of 4 passwords with 8 characters in each of them.

Image

The command is responsible for generating a list of random passwords based on the number of passwords we want to generate and the length is also defined by us.

Conclusion

In this tutorial, we have discussed many of the ways to generate the passwords from the command line of Linux. There are many methods that already exist. Few of the utilities are already present in Linux command line, while for those which are not are easily installable using the available commands. In the tutorial, we have discussed the utility openssh, urandom, pwegn, gpg, sha, date, apg, and makepasswd. All of these commands guarantee the generation of a stronger password from Linux command line and are useful for the user to maintain the security of their systems.

More about passwords

Purpose

Using authentication to secure data and accounts has grown to be a natural part of computing. Even if several authentication methods are in existence, using passwords remains the most common type of authentication. As long and complex passwords are encouraged by research studies and practitioners alike, computer users design passwords using strategies that enable them to remember their passwords. This paper aims to present a taxonomy of those password creation strategies in the form of a model describing various strategies used to create passwords.

Design/methodology/approach

The study was conducted in a three-step process beginning with a short survey among forensic experts within the Swedish police. The model was then developed by a series of iterative semi-structured interviews with forensic experts. In the third and final step, the model was validated on 5,000 passwords gathered from 50 different password databases that have leaked to the internet.

Findings

The result of this study is a taxonomy of password creation strategies presented as a model that describes the strategies as properties that a password can hold. Any given password can be classified as holding one or more of the properties outlined in the model.

Originality/value

On an abstract level, this study provides insight into password creation strategies. As such, the model can be used as a tool for research and education. It can also be used by practitioners in, for instance, penetration testing to map the most used password creation strategies in a domain or by forensic experts when designing dictionary attacks.

Another interesting article may be: 6 Best Password Managers For Linux Desktop

If you want to comment: Login or Register