Learn to generate random passwords using 8 Linux native commands or third-party utilities

Learn how to generate random passwords using eight native Linux commands or third-party utilities. This article will guide you through various methods of creating secure passwords directly from the Linux terminal. Some techniques use built-in Linux tools, while others rely on external applications that can be easily installed on your system.

The tools we'll explore include native commands such as openssl, dd, md5sum, tr, urandom, and others, as well as third-party utilities like mkpasswd, randpw, pwgen, spw, gpg, xkcdpass, diceware, revelation, keepaasx, and passwordmaker. These methods are designed to create random strings that can serve as strong passwords for new users or other purposes where uniqueness is essential.

Generating a password using mkpasswd:

Mkpasswd is part of the expect package on RHEL-based systems and included in the whois package on Debian-based systems. If you encounter an error when trying to install mkpasswd directly, it’s better to install the parent package instead.

For example, on RHEL systems, run:

root@kerneltalks# mkpasswd

Output: Zt*hGW65c

On Ubuntu, you can pass a string to customize the output:

root@kerneltalks# mkpasswd teststring

Output: XnlrKxYOJ3vik

This command may behave differently on various systems, so it's recommended to consult the man page for more options and customization.

Using openssl to generate a password:

OpenSSL is widely available across most Linux distributions. It can generate a base64-encoded random string suitable for use as a password.

Example command:

root@kerneltalks# openssl rand -base64 10

Output: nU9LlHO5nsuUvw==

Here, the number at the end specifies the length of the generated password.

Generating a password using /dev/urandom:

The /dev/urandom device provides a way to generate random data. Combined with the tr command, it can be used to filter and extract alphanumeric characters.

Command example:

root@kerneltalks# strings /dev/urandom | tr -dc A-Za-z0-9 | head -c 20; echo

Output: UiXtr0NAOSIkqtjK4c0X

This method allows you to control the length of the password by adjusting the 'head -c' parameter.

Using the dd command:

You can also use the dd command along with /dev/urandom to generate random strings. For example:

root@kerneltalks# dd if=/dev/urandom bs=1 count=15 | base64 -w 0

Output: F8c3a4joS+a3BdPN9C++

To clean up the output, redirect standard error to /dev/null:

root@kerneltalks# dd if=/dev/urandom bs=1 count=15 2>/dev/null | base64 -w 0

Output: QMsbe2XbrqAc2NmXp8D0

Generating a password using md5sum:

Another approach involves using the md5sum utility. By generating a checksum from a variable source like the date command, you can create a pseudo-random string.

Example:

root@kerneltalks# date | md5sum

Output: 4d8ce5c42073c7e9ca4aeffd3d157102 -

You can use the cut command to adjust the length of the output as needed.

Using pwgen:

Pwgen is a tool that generates pronounceable passwords. Although not always found in default repositories, it can be installed and used to generate multiple passwords at once.

Example command:

root@kerneltalks# pwgen

Output includes a list of randomly generated passwords such as: thu8Iox7, ahDeeQu8, Eexoh0ai, etc.

Using gpg:

GPG is a powerful encryption tool that can also be used to generate random byte sequences. The command below generates a base64-encoded random string:

root@kerneltalks# gpg --gen-random --armor 1 12

Output: mL8i+PKZ3IuN6a7a

This method ensures high-quality randomness and is suitable for generating secure passwords.

Using xkcdpass:

Inspired by the popular xkcd comic about memorable passwords, xkcdpass generates passwords based on dictionary words. It is a Python-based tool that can be installed from PyPI.

After installation, running xkcdpass will provide a list of random words that can be combined into a strong password. For example:

root@kerneltalks# xkcdpass

Output: Broadside unpadded osmosis statistic cosmetics lugged

These words can be further processed using commands like md5sum to enhance their security or used directly as a memorable password.

Automation Light Curtain

This Automation curtain is specially designed for automation industry. SDKELI LSC2 light curtain is designed for automation field, with small size, compact structure and strong anti-interference ability, and the product meets IEC 61496-2 standards. The automatic light curtain is with reliable quality and very competitive price. It has been used in many factories.

Automatic Light Curtain,Laser Light Curtain,Automation Light Beam Sensor,Automatic Infrared Beam Sensor,Infrared Beam Curttain Sensor,Infrared Beam Sensor

Jining Keli Photoelectronic Industrial Co.,Ltd , https://www.sdkelien.com

Posted on