5 Ways To Generate A Random/Strong Password In Linux Terminal
======
Recently we had written an article about **[password strength and password score check][1]** in our website.
It will help you to validate your password strength and score.
We can manually create few passwords which we required but if you would like to generate a password for multiple users or servers, what will be the solution.
Yes, there are many utilities are available in Linux to fulfill this requirements. However, I’m going to include the best five password generators in this article.
These tools are generates a strong random passwords for you. Navigate to the following article if you would like to update the password on multiple users and servers.
These tools are easy to use, that’s why i preferred to go with it. By default it will generate a strong password and if you would like to generate a super strong password then use the available options.
It will help you to generate a super strong password in the following combination. It should have minimum 12-15 characters length, that includes Alphabets (Lower case & Upper case), Numbers and Special Characters.
These tools are below.
*`pwgen:` The pwgen program generates passwords which are designed to be easily memorized by humans, while being as secure as possible.
*`openssl:` The openssl program is a command line tool for using the various cryptography functions of OpenSSL’s crypto library from the shell.
*`gpg:` OpenPGP encryption and signing tool
*`mkpasswd:` generate new password, optionally apply it to a user
*`makepasswd:` makepasswd generates true random passwords using /dev/urandom, with the emphasis on security over pronounceability.
*`/dev/urandom file:` The character special files /dev/random and /dev/urandom (present since Linux 1.3.30) provide an interface to the kernel’s random number generator.
*`md5sum:` md5sum is a computer program that calculates and verifies 128-bit MD5 hashes.
*`sha256sum:` The program sha256sum is designed to verify data integrity using the SHA-256 (SHA-2 family with a digest length of 256 bits).
*`sha1pass:` sha1pass creates a SHA1 password hash. In the absence of a salt value on the command line, a random salt vector will be generated.
### How To Generate A Random Strong Password In Linux Using pwgen Command?
The pwgen program generates passwords which are designed to be easily memorized by humans, while being as secure as possible.
Human-memorable passwords are never going to be as secure as completely completely random passwords.
Use `-s` option to generate completely random, hard-to-memorize passwords. These should only be used for machine passwords as we can’t memorize.
For **`Fedora`** system, use **[DNF Command][2]** to install pwgen.
```
$ sudo dnf install pwgen
```
For **`Debian/Ubuntu`** systems, use **[APT-GET Command][3]** or **[APT Command][4]** to install pwgen.
```
$ sudo apt install pwgen
```
For **`Arch Linux`** based systems, use **[Pacman Command][5]** to install pwgen.
```
$ sudo pacman -S pwgen
```
For **`RHEL/CentOS`** systems, use **[YUM Command][6]** to install pwgen.
```
$ sudo yum install pwgen
```
For **`openSUSE Leap`** system, use **[Zypper Command][7]** to install pwgen.
```
$ sudo zypper install pwgen
```
### How To Use pwgen Command In Linux?
It’s a simple and straight forward method. Use one of the below preferred examples for you. By default, it generates a human memorable password.
To do so, simple run the `pwgen` command on your terminal. It generates 160 passwords in a single shot. These 160 passwords are printer with 20 rows and 8 columns.
### How To Generate A Random Strong Password In Linux Using openssl Command?
The openssl program is a command line tool for using the various cryptography functions of OpenSSL’s crypto library from the shell.
Run the openssl command with the following format to generate a random strong password with 14 characters.
```
$ openssl rand -base64 14
WjzyDqdkWf3e53tJw/c=
```
If you would like to generate ten random strong password with 14 characters using openssl command then use the following for loop.
```
$ for pw in {1..10}; do openssl rand -base64 14; done
6i0hgHDBi3ohZ9Mil8I=
gtn+y1bVFJFanpJqWaA=
rYu+wy+0nwLf5lk7TBA=
xrdNGykIzxaKDiLF2Bw=
cltejRkDPdFPC/zI0Pg=
G6aroK6d4xVVYFTrZGs=
jJEnFoOk1+UTSx/wJrY=
TFxVjBmLx9aivXB3yxE=
oQtOLPwTuO8df7dIv9I=
ktpBpCSQFOD+5kIIe7Y=
```
### How To Generate A Random Strong Password In Linux Using gpg Command?
gpg is the OpenPGP part of the GNU Privacy Guard (GnuPG). It is a tool to provide digital encryption and signing services using the OpenPGP standard. gpg features complete key management and all the bells and whistles you would expect from a full OpenPGP implementation.
Run the gpg command with the following format to generate a random strong password with 14 characters.
```
$ gpg --gen-random --armor 1 14
or
$ gpg2 --gen-random --armor 1 14
jq1mtY4gBa6gIuJrggM=
```
If you would like to generate ten random strong password with 14 characters using gpg command then use the following for loop.
```
$ for pw in {1..10}; do gpg --gen-random --armor 1 14; done
or
$ for pw in {1..10}; do gpg2 --gen-random --armor 1 14; done
F5ZzLSUMet2kefG6Ssc=
8hh7BFNs8Qu0cnrvHrY=
B+PEt28CosR5xO05/sQ=
m21bfx6UG1cBDzVGKcE=
wALosRXnBgmOC6+++xU=
TGpjT5xRxo/zFq/lNeg=
ggsKxVgpB/3aSOY15W4=
iUlezWxL626CPc9omTI=
pYb7xQwI1NTlM2rxaCg=
eJjhtA6oHhBrUpLY4fM=
```
### How To Generate A Random Strong Password In Linux Using mkpasswd Command?
mkpasswd generates passwords and can apply them automatically to users. With no arguments, mkpasswd returns a new password. It’s part of an expect package so, you have to install expect package to use mkpasswd command.
For **`Fedora`** system, use **[DNF Command][2]** to install mkpasswd.
```
$ sudo dnf install expect
```
For **`Debian/Ubuntu`** systems, use **[APT-GET Command][3]** or **[APT Command][4]** to install mkpasswd.
```
$ sudo apt install expect
```
For **`Arch Linux`** based systems, use **[Pacman Command][5]** to install mkpasswd.
```
$ sudo pacman -S expect
```
For **`RHEL/CentOS`** systems, use **[YUM Command][6]** to install mkpasswd.
```
$ sudo yum install expect
```
For **`openSUSE Leap`** system, use **[Zypper Command][7]** to install mkpasswd.
```
$ sudo zypper install expect
```
Run the `mkpasswd` command in terminal to generate a random password.
```
$ mkpasswd
37_slQepD
```
Run the mkpasswd command with the following format to generate a random strong password with 14 characters.
```
$ mkpasswd -l 14
W1qP1uv=lhghgh
```
Run the mkpasswd command with the following format to generate a random strong password with 14 characters. It combinations of alphabetic (Lower & Upper case), Numeric number and special characters.
```
$ mkpasswd -l 14 -d 3 -C 3 -s 3
3aad!bMWG49"t,
```
If you would like to generate ten random strong password with 14 characters (It combination of alphabetic (Lower & Upper case), Numeric number and special characters) using mkpasswd command then use the following for loop.
```
$ for pw in {1..10}; do mkpasswd -l 14 -d 3 -C 3 -s 3; done
zmSwP[q9;P1r6[
E42zcvzM"i3%B\
8}1#[emailprotected]
0X:zB(mmU22?nj
0sqqL44M}ko(O^
43tQ(.6jG;ceRq
-jB6cp3x1GZ$e=
$of?Rj9kb2N(1J
9HCf,nn#gjO79^
Tu9m56+Ev_Yso(
```
### How To Generate A Random Strong Password In Linux Using makepasswd Command?
makepasswd generates true random passwords using /dev/urandom, with the emphasis on security over pronounceability. It can also encrypt plaintext passwords given on the command line.
Run the `makepasswd` command in terminal to generate a random password.
```
$ makepasswd
HdCJafVaN
```
Run the makepasswd command with the following format to generate a random strong password with 14 characters.
```
$ makepasswd --chars 14
HxJDv5quavrqmU
```
Run the makepasswd command with the following format to generate ten random strong password with 14 characters.
```
$ makepasswd --chars 14 --count 10
TqmKVWnRGeoVNr
mPV2P98hLRUsai
MhMXPwyzYi2RLo
dxMGgLmoFpYivi
8p0G7JvJjd6qUP
7SmX95MiJcQauV
KWzrh5npAjvNmL
oHPKdq1uA9tU85
V1su9GjU2oIGiQ
M2TMCEoahzLNYC
```
### How To Generate A Random Strong Password In Linux Using Multiple Commands?
Still if you are looking other options then you can use the following utilities to generate a random password in Linux.
**Using md5sum:** md5sum is a computer program that calculates and verifies 128-bit MD5 hashes.
```
$ date | md5sum
9baf96fb6e8cbd99601d97a5c3acc2c4 -
```
**Using /dev/urandom:** The character special files /dev/random and /dev/urandom (present since Linux 1.3.30) provide an interface to the kernel’s random number generator. File /dev/random has major device number 1 and minor device number 8. File /dev/urandom has major device number 1 and minor device number 9.