We all know how important it is to use strong passwords for our systems, online accounts, and other sensitive applications. The real deal is how to generate a password that you can rely on and the one that follows the criteria of a strong password. Ideally, a strong password must contain lower case, upper case letter, numbers, and symbols. If this task seems tiresome for you to do manually, Ubuntu provides many ways through which you can automatically generate such strong passwords.

This article describes 7 such ways of automatic password generation.

We have run the commands and procedures mentioned in this article on a Ubuntu 18.04 LTS system. Most of the methods mentioned here include the use of the Ubuntu command line, the Terminal, for installing and using a password generating utility. You can open the Terminal application either through the system Dash or the Ctrl+Alt+T shortcut.

Note: Before installing any software through the apt-get command, it is best to update your system repositories with the following command:

$ sudo apt-get update

This way you will be able to add the latest available version of a software.

Method 1: Using OpenSSL

In order to generate a random password through the OpenSSL utility, enter the following command in your Terminal:

$ openssl rand -base64 14

Here,

  • rand will generate a random password
  • -base64 ensures that the password format can be typed through a keyboard
  • 14 is the length of the password

Although OpenSSL comes with most Linux distros, your system might lack the rand utility and thus the above-mentioned command might not work for you. You can, however, install it through the following command as sudo:

$ sudo apt install rand

using rand command to generate a strong password

Method 2: Using the pwgen utility

The pwgen utility helps you in generating strong and easily memorable passwords in seconds. You can install this utility through the following command

$ sudo apt-get install pwgen

Install pwgen

The pwgen help contains many options through which you can customize the password. Here is how to use this command:

$ pwgen [ OPTIONS ] [ pw_length ] [ num_pw ]

And, here is how you can see the help:

$ pwgen --help

For example, the following command will generate one 14 letter password.

$ pwgen 14 1

Generate a secure password with pwgen

The best way to generate a password, in our opinion, is to use the following command:

$ pwgen -ys 15 1

We have used two options for pwgen in this command; the y flag tells pwgen to generate a secure password and s tells it to come up with a password that includes symbols.

Very strong password generated with pwgen on Linux command line

You can see in the output how complicated, and thus strong, the password is.

Method 3: Using the GPG utility

GPG or GNU Privacy Guard is a free command line utility through which you can generate strong passwords in your Linux, Microsoft Windows, and Android systems. By running the following command in your Terminal, you can generate a strong random password of 14 characters, with an ascii armored output:

$ gpg --gen-random --armor 1 14

Using gpg to generate a secure password

Method 4: Using the perl utility

Perl is a command line utility that is available in the official Ubuntu repositories. You can download it through the following command:

$ sudo apt-get install perl

Install perl

The above output indicates that perl is available on my Ubuntu 18.04 by default.

So how do we use it to generate a secure password?

First, let us create a perl program by opening a new file through any of the text editors. We are creating a file named passwordgen.pl through the Nano editor as follows:

$ nano passwordgen.pl

In your file copy and paste the following perl nugget:

#!/usr/bin/perl
my @alphanumeric = ('a'..'z', 'A'..'Z', 0..9);
my $randpassword = join '', map $alphanumeric[rand @alphanumeric], 0..8;
print "$randpassword\n"

I found these lines on the Internet from an unknown author, but I must say that they proved to be really helpful. Anyway, save the .pl file when you are done.

Generate random password with perl

For Nano, you can exit the file by using the Ctrl+X shortcut and then by entering Y in order to save the changes.

Now run the following command in order to run your perl program:

$ perl passwordgen.pl

Password generated using perl programming language

The output is a secure password that you can use anywhere.

Method 5: Using the Revelation UI Application

The password generation methods that we have mentioned so far are all CLI based. Now, look at a few methods through which you can get a password through the UI. Revelation is a password management GUI tool for Gnome through which you can generate a customized strong password.

You can install the application by entering the following command in the Terminal:

$ sudo apt-get install revelation

Install Revelation

Please enter Y if the system prompts you with a Y/n option.

You can then launch the application either through the Terminal or the Ubuntu Dash.

When the application opens, first go to the View menu and select the Show Passwords option. This will let you view the generated password in a visual form, rather than in hidden asterisks format. Then select the Password Generator option from the View menu. In the Password Generator dialog, you can set the length of the password and also specify if you want to include punctuation characters/symbols in your password.

Revelation password Generator

You can then click the Generate button in order to generate a custom password.

Method 6: Using the UI Keepassx application

The Keepassx is a cross-platform password management solution. It keeps your password in a database and encrypts it by using Twofish and AES algorithms. Here is how you can install it through the command line:

$ sudo apt-get install keepassx

Installing Keepassx

Please enter Y if the system prompts you with a Y/n option. Once the installation completes, you can open the application either through the Terminal or the system Dash.

Generating a password through this software requires you to perform a few preliminary steps. First, you need to create a new database through the Database menu. Then you need to create a new group through the Groups menu. After that, select the Add new entry through the Entries menu. In the view that you will see, click on the Gen button in order to generate a password. Generate secure password in keepassx application

The best part about this software is that you can graphically select if you want to include capital letters, small letters, numerals, and symbols in your password. You can also specify if you want to emit look-alike characters and also ensure that the password contains characters from all the specified character options.

So now you are not short of ways through which you can generate a strong and secure password to be used anywhere on the Internet or local applications. We recommend that you do not keep these passwords saved to any file in your system as it might make them prone to attack by hackers. A tip to get even stronger passwords is to combine strings from passwords generated through a few different tools.

7 Methods to Generate a Strong Password in Ubuntu