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

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

In this article, we will guide you through the generation of random passwords in Linux terminals in several different ways. Several of them utilize native Linux commands, while others are implemented using third-party tools or utilities that are easily installed on Linux machines. Here we use native commands like openssl, dd, md5sum, tr, urandom and third-party tools like mkpasswd, randpw, pwgen, spw, gpg, xkcdpass, diceware, revelation, keepaasx, passwordmaker.

In fact, these methods are to generate some random letter strings that can be used as passwords. Random passwords can be used for new user passwords, which are unique regardless of the user base. Not much to say, let's take a look at 8 different ways to generate random passwords on Linux.

Generate a password using the mkpasswd utility

Mkpasswd is installed with the expect package on RHEL-based systems. On Debian-based systems mkpasswd is in the package whois. Installing the mkpasswd package directly will result in an error:

RHEL system: The package mkpasswd is not available.

Debian system: Error: Unable to locate package mkpasswd.

So installing their parent package as described above is fine.

Run mkpasswd to get the password

Root@kerneltalks# mkpasswd << on RHEL

Zt*hGW65c

Root@kerneltalks# mkpasswd teststring << on Ubuntu

XnlrKxYOJ3vik

This command does not work the same on different systems, so it works differently. You can also control options such as length by parameters, which you can explore by consulting the man page.

Generate passwords using openssl

Nearly all Linux distributions include openssl. We can use its random function to generate a random alphabetic string that can be used as a password.

Root@kerneltalks# openssl rand -base64 10

nU9LlHO5nsuUvw==

Here we use a base64 encoded random function, the last numeric parameter representing the length.

Generate password using urandom

The device file /dev/urandom is another way to get a random string. We use the tr function and crop the output to get a random string and use it as a password.

Root@kerneltalks# strings /dev/urandom |tr -dc A-Za-z0-9 | head -c20; echo

UiXtr0NAOSIkqtjK4c0X

Generate a password using the dd command

We can even use the /dev/urandom device with the dd command to get a random string.

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

15+0records in

15+0records out

15bytes(15B)copied, 5.5484e-05s, 270kB/s

QMsbe2XbrqAc2NmXp8D0

We need to base the result in base64 encoding to make it human readable. You can use the values ​​to get the length you want. For a cleaner output, you can redirect the "standard error output" to /dev/null. The commands for simple output are:

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

F8c3a4joS+a3BdPN9C++

Generate a password using md5sum

Another way to get a random string that can be used as a password is to calculate the MD5 checksum! The checksums look like they are grouped together as random strings, which we can use as passwords. Make sure your calculation source is a variable so that the checksum generated each time you run the command is different. Such as date! The date command always produces different output.

Root@kerneltalks# date |md5sum

4d8ce5c42073c7e9ca4aeffd3d157102 -

Here we get the checksum output from the date command via md5sum! You can also use the cut command to crop the length you need.

Generate passwords using pwgen

The pwgen package is similar to the EPEL software repository (LCTT). Pwgen is more focused on generating pronunciationable passwords, but they are not in the English dictionary, nor in English. This tool may not be included in the standard release repository. Install this package and run the pwgen command line. Boom!

Root@kerneltalks# pwgen

thu8Iox7 ahDeeQu8 Eexoh0ai oD8oozie ooPaeD9t meeNeiW2 Eip6ieph Ooh1tiet

cootad7O Gohci0vo wah9Thoh Ohh3Ziur Ao1thoma ojoo6aeW Oochai4v ialaiLo5

aic2OaDa iexieQu8 Aesoh4Ie Eixou9ph ShiKoh0i uThohth7 taaN3fuu Iege0aeZ

cah3zaiW Eephei0m AhTh8guo xah1Shoo uh8Iengo aifeev4E zoo4ohHa fieDei6c

aorieP7k ahna9AKe uveeX7Hi Ohji5pho AigheV7u Akee9fae aeWeiW4a tiex8Oht

Your terminal will present a list of passwords! What else do you want? Ok. If you want to explore it again, pwgen has a lot of customization options, which can be found in the man page.

Generate a password using the gpg tool

GPG is an encryption and signature tool that follows the OpenPGP standard. Most gpg tools are pre-installed (at least on my RHEL7). But if not, you can look for the gpg or gpg2 package and install it.

Use the following command to generate a password from the gpg tool.

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

mL8i+PKZ3IuN6a7a

Here we pass the option to generate a random byte sequence (--gen-random) with a quality of 1 (the first parameter) and a number of 12 (the second parameter). The option --armor guarantees output in base64 encoding.

Generate a password using xkcdpass

The famous geek humor website xkcd has published a very interesting article about easy-to-remember but complicated passwords. So the xkcdpass tool was inspired by this article and did the work like this! This is a Python package that can be found on Python's website.

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

Here is the installation steps and the output of my test RHEL server for reference.

Root@kerneltalks# wget https://pypi.python.org/packages/b4/d7/3253bd2964390e034cf0bba227db96d94de361454530dc056d8c1c096abc/xkcdpass-1.14.3.tar.gz#md5=5f15d52f1d36207b07391f7a25c7965f

--2018-01-2319:09:17-- https://pypi.python.org/packages/b4/d7/3253bd2964390e034cf0bba227db96d94de361454530dc056d8c1c096abc/xkcdpass-1.14.3.tar.gz

Resolving pypi.python.org(pypi.python.org)...151.101.32.223,2a04:4e42:8::223

Connecting topypi.python.org(pypi.python.org)|151.101.32.223|:443...connected.

HTTP request sent, awaiting response...200OK

Length: 871848(851K)[binary/octet-stream]

Saving to: 'xkcdpass-1.14.3.tar.gz'

100%[======================================================== =========================================================== ===============================]]871,848 --.-K/s in0.01s

2018-01-2319:09:17 (63.9MB/s) - 'xkcdpass-1.14.3.tar.gz'saved[871848/871848]

Root@kerneltalks# tar -xvf xkcdpass-1.14.3.tar.gz

Xkcdpass-1.14.3/

Xkcdpass-1.14.3/examples/

Xkcdpass-1.14.3/examples/example_import.py

Xkcdpass-1.14.3/examples/example_json.py

Xkcdpass-1.14.3/examples/example_postprocess.py

Xkcdpass-1.14.3/LICENSE.BSD

Xkcdpass-1.14.3/MANIFEST.in

Xkcdpass-1.14.3/PKG-INFO

Xkcdpass-1.14.3/README.rst

Xkcdpass-1.14.3/setup.cfg

Xkcdpass-1.14.3/setup.py

Xkcdpass-1.14.3/tests/

Xkcdpass-1.14.3/tests/test_list.txt

Xkcdpass-1.14.3/tests/test_xkcdpass.py

Xkcdpass-1.14.3/tests/__init__.py

Xkcdpass-1.14.3/xkcdpass/

Xkcdpass-1.14.3/xkcdpass/static/

Xkcdpass-1.14.3/xkcdpass/static/eff-long

Xkcdpass-1.14.3/xkcdpass/static/eff-short

Xkcdpass-1.14.3/xkcdpass/static/eff-special

Xkcdpass-1.14.3/xkcdpass/static/fin-kotus

Xkcdpass-1.14.3/xkcdpass/static/ita-wiki

Xkcdpass-1.14.3/xkcdpass/static/legacy

Xkcdpass-1.14.3/xkcdpass/static/spa-mich

Xkcdpass-1.14.3/xkcdpass/xkcd_password.py

Xkcdpass-1.14.3/xkcdpass/__init__.py

Xkcdpass-1.14.3/xkcdpass.1

Xkcdpass-1.14.3/xkcdpass.egg-info/

Xkcdpass-1.14.3/xkcdpass.egg-info/dependency_links.txt

Xkcdpass-1.14.3/xkcdpass.egg-info/entry_points.txt

Xkcdpass-1.14.3/xkcdpass.egg-info/not-zip-safe

Xkcdpass-1.14.3/xkcdpass.egg-info/PKG-INFO

Xkcdpass-1.14.3/xkcdpass.egg-info/SOURCES.txt

Xkcdpass-1.14.3/xkcdpass.egg-info/top_level.txt

Root@kerneltalks# cd xkcdpass-1.14.3

Root@kerneltalks# python setup.py install

Running install

Running bdist_egg

Running egg_info

Writing xkcdpass.egg-info/PKG-INFO

Writing top-level names toxkcdpass.egg-info/top_level.txt

Writing dependency_links toxkcdpass.egg-info/dependency_links.txt

Writing entry points toxkcdpass.egg-info/entry_points.txt

Reading manifest file'xkcdpass.egg-info/SOURCES.txt'

Reading manifest template'MANIFEST.in'

Writing manifest file'xkcdpass.egg-info/SOURCES.txt'

Installer library code tobuild/bdist.linux-x86_64/egg

Running install_lib

Running build_py

Creating build

Creating build/lib

Creating build/lib/xkcdpass

Copying xkcdpass/xkcd_password.py -> build/lib/xkcdpass

Copying xkcdpass/__init__.py -> build/lib/xkcdpass

Creating build/lib/xkcdpass/static

Copying xkcdpass/static/eff-long -> build/lib/xkcdpass/static

Copying xkcdpass/static/eff-short -> build/lib/xkcdpass/static

Copying xkcdpass/static/eff-special -> build/lib/xkcdpass/static

Copying xkcdpass/static/fin-kotus -> build/lib/xkcdpass/static

Copying xkcdpass/static/ita-wiki -> build/lib/xkcdpass/static

Copying xkcdpass/static/legacy -> build/lib/xkcdpass/static

Copying xkcdpass/static/spa-mich -> build/lib/xkcdpass/static

Creating build/bdist.linux-x86_64

Creating build/bdist.linux-x86_64/egg

Creating build/bdist.linux-x86_64/egg/xkcdpass

Copying build/lib/xkcdpass/xkcd_password.py -> build/bdist.linux-x86_64/egg/xkcdpass

Copying build/lib/xkcdpass/__init__.py -> build/bdist.linux-x86_64/egg/xkcdpass

Creating build/bdist.linux-x86_64/egg/xkcdpass/static

Copying build/lib/xkcdpass/static/eff-long -> build/bdist.linux-x86_64/egg/xkcdpass/static

Copying build/lib/xkcdpass/static/eff-short -> build/bdist.linux-x86_64/egg/xkcdpass/static

Copying build/lib/xkcdpass/static/eff-special -> build/bdist.linux-x86_64/egg/xkcdpass/static

Copying build/lib/xkcdpass/static/fin-kotus -> build/bdist.linux-x86_64/egg/xkcdpass/static

Copying build/lib/xkcdpass/static/ita-wiki -> build/bdist.linux-x86_64/egg/xkcdpass/static

Copying build/lib/xkcdpass/static/legacy -> build/bdist.linux-x86_64/egg/xkcdpass/static

Copying build/lib/xkcdpass/static/spa-mich -> build/bdist.linux-x86_64/egg/xkcdpass/static

Byte-compiling build/bdist.linux-x86_64/egg/xkcdpass/xkcd_password.py toxkcd_password.pyc

Byte-compiling build/bdist.linux-x86_64/egg/xkcdpass/__init__.py to__init__.pyc

Creating build/bdist.linux-x86_64/egg/EGG-INFO

Copying xkcdpass.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO

Copying xkcdpass.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO

Copying xkcdpass.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO

Copying xkcdpass.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO

Copying xkcdpass.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO

Copying xkcdpass.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO

Creating dist

Creating'dist/xkcdpass-1.14.3-py2.7.egg'andadding'build/bdist.linux-x86_64/egg'toit

Removing'build/bdist.linux-x86_64/egg'(andeverything under it)

Processing xkcdpass-1.14.3-py2.7.egg

Creating /usr/lib/python2.7/site-packages/xkcdpass-1.14.3-py2.7.egg

Extracting xkcdpass-1.14.3-py2.7.eggto /usr/lib/python2.7/site-packages

Adding xkcdpass1.14.3toeasy-install.pth file

Installing xkcdpass script to /usr/bin

Installed /usr/lib/python2.7/site-packages/xkcdpass-1.14.3-py2.7.egg

Processing dependencies forxkcdpass==1.14.3

Finished processing dependencies forxkcdpass==1.14.3

Now run the xkcdpass command, which will randomly give you several dictionary words like the following:

Root@kerneltalks# xkcdpass

Broadside unpadded osmosis statistic cosmetics lugged

You can use these words as other commands, such as the input of md5sum, to get a random password (as shown below), or even you can use the Nth letter of each word to generate your password!

Root@kerneltalks# xkcdpass |md5sum

45f2ec9b3ca980c7afbd100268c74819 -

Root@kerneltalks# xkcdpass |md5sum

Ad79546e8350744845c001d8836f2ff2 -

Or you can even string all the words together as a very long password, not only very easy to remember, but also not easily broken by computer programs.

There are also tools like Diceware, KeePassX, Revelation, PasswordMaker on Linux, which can also be considered for generating strong random passwords.

Anti-microbial Film

Bacteria are everywhere in our daily lives. Mobile phones have become an indispensable item for us. Of course, bacteria will inevitably grow on the phone screen. The antimicrobial coating used in our Anti Microbial Screen Protector can reduce 99% of the bacterial growth on the screen, giving you more peace of mind.

Self-healing function

The Screen Protector can automatically repair tiny scratches and bubbles within 24 hours.

Clear and vivid

A transparent protective layer that provides the same visual experience as the device itself.

Sensitive touch

The 0.14mm Ultra-Thin Protective Film can maintain the sensitivity of the touch screen to accurately respond to your touch. Like swiping on the device screen.

Oleophobic and waterproof

Anti-fingerprint and oil-proof design can help keep the screen clean and clear.

If you want to know more about Anti Microbial Screen Protector products, please click Product Details to view the parameters, models, pictures, prices and other information about Anti Microbial Screen Protector products.

Whether you are a group or an individual, we will try our best to provide you with accurate and comprehensive information about Anti Microbial Screen Protector!

Antimicrobial Screen Protector, Anti-microbial Screen Protector, Anti-bacterial Screen Protector, Antibacterial Screen Protector,Anti-microbial Hydrogel Screen Protector

Shenzhen Jianjiantong Technology Co., Ltd. , https://www.jjthydrogelprotector.com

Posted on