Tag Archives: Linux How to

Unix Similar multi-user operating systems based on the Linux kernel and essentially on GNU software. Like CentOS, Debian, Ubuntu Fedora.

Generate random password using 10 methods in Linux

Generate Random Password using Strong Password Generator

Generate random password using 5 methods in Linux

You can manually create some of the passwords you need. However, if you want to generate a secure password for multiple users or devices, then this is not an adequate approach.

There are many Linux utilities on the web that meet these requirements. In this tutorial I will introduce the 10 best password generators, which can be used in the Linux terminal.

The following combinations will help you generate a strong password. It should be at least 10-16 characters long, including alphabets (lowercase and uppercase), numbers, and special characters.

The 10 best strong password generators

pwgen generate strong passwords that are easy for people to remember and at the same time as secure as possible.
xkcdpass uses 12 dictionaries by Aspell, the GNU spell checker project.
openssl commonly used for the various cryptography operations of OpenSSL cryptography library.
gpg used the OpenPGP encryption and signing tool.
mkpasswd create new password, can optionally be applied to a user.
makepasswd create true randomized passwords using /dev/urandom, with the accent on security over pronounceability.
md5sum calculates and verifies 128-bit MD5 hashes.
sha256sum verify data integrity using the SHA-256.
sha1pass is known to create SHA1 hash.
/dev/urandom file use character special files /dev/random to provide an interface to the kernel random number generator.

Generate strong password using pwgen

The pwgen program generates passwords in a way that people can easily remember, while being as secure as possible. For most systems, pwgen needs to be installed first.

$ sudo apt install pwgen

To do so, simple run the pwgen command in the Linux terminal. It generates 160 secure passwords in a single shot. These 160 passwords are printed in 20 rows and 8 columns.

Generate strong 6 passwords with 16 characters length. Use -s option to generate completely random, hard-to-memorize words. Run the pwgen command as follows.

$ pwgen -s 16 4
0mvQIiWNoMLxbgVR rZ7REDOdjmvOr79D JOX9aPy7dYwRzISF yZBwXb5EwrcM4h3j

If you want to generate 10 random passwords with 16 characters length, including numbers, and special characters, use these pwgen command.

$ pwgen -cnys 16 12
:38M*BA-6y90WyOl U;2+rT/~3j3|}Y)I Zqr>I0p[Ls{IF?z5 c'Zy<%`BK/4>gJ~E
4s|,{h4hQuv@UGIy la!0mH;qSF1!>F|O v@l_8Uf3DH.\}fR L"(hvNI!aafXI0ru
4"Z`[qywLRLA17VC PC>y3[o0{)/i\bN{ iRF+85e<7'of14:p G.6aC:KLG/>49Smb

Create random password using xkcdpass

xkcdpass uses the dict2 and dict6 word list by default due to their unique properties. It has an option that could be used. It can be combined with the output of pwgen to get unique passwords too. You can also use the first letter of each word of the passphrase to create a password that is also easy to remember.

Commonly the xkcdpass program has to be installed first.

$ sudo apt install xkcdpass

If you hit and run xkcdpass then 6 passwords will be displayed.

$ xkcdpass
pellet lunchroom epidemic viable jawless jumbo

xkcdpass can even be used interactively, with the -i option it asks you how many words it should generate and whether it should continue generating with ask y/N and loop until one is accepted.

$ xkcdpass -i
Enter number of words (default 6): 12
Generated: employer celibacy hypertext liqueur bounce tightrope probiotic pencil provoke spotless jawless endnote
Accept? [yN] n
Generated: concrete edginess reanalyze hatred possibly tadpole reword fresh glory casually duckling overstuff
Accept? [yN] y
concrete edginess reanalyze hatred possibly tadpole reword fresh glory casually duckling overstuff

Create random password using OpenSSL

Using OpenSSL to create secure passwords, with run the following command to create a random password with 16 characters lenght.

$ openssl rand -base64 16
8buZwXt+OKjdN9MxxuRRTw==

If you would like to generate 10 random password with 16 characters length using openssl, then ran the openssl command in a for loop.

$ for pw in {1..10}; do openssl rand -base64 16; done

Create strong password using gpg

Run the gpg program with the following command to generate a random password with 16 characters length.

$ gpg --gen-random --armor 1 16
huH4efPrgPDTNAmQU8u1ng==

Generate random password using mkpasswd

mkpasswd generates passwords and can apply them automatically to users. It’s part of the whois package so you need to install first.

$ sudo apt install whois

With no arguments, mkpasswd returns a new password. Run the mkpasswd command with hit Enter as follows.

$ mkpasswd
Password:
bDu7vypaEAWxQ

Run the mkpasswd with the following command to generate a random password with 16 characters length.

$ mkpasswd 16
YjXEEmcQGfsh6

Generate random password using makepasswd

Commonly the makepasswd program has to be installed first.

$ sudo apt install makepasswd

Run makepasswd command in terminal to generate a random password.

$ makepasswd
mtrn2vCN

Run makepasswd with the following command to generate 10 random password with 16 characters length.

$ makepasswd --chars 16 --count 10
8FeKPTsPWWnMzwPd
IzJYdQ5ugp54QL2V
to4JD057ivK97ebw
X0i8jBiALTTqJQXy
dSPpu9sVRyxuW1gs
m6f4ppv4VmAJRDBr
N21WjEES1R3CpR4b
LV5IeQ2u9B4teSSY
bpJ2pAML4InuTLMC
W8rxuaatQxU0sB1h

Generate random password using md5sum

md5sum is a computer program that calculates and verifies 128-bit MD5 hashes.

$ date | md5sum
09f9d8063cd64c4f45156e1694e405e8  -

Create strong password using sha256sum

sha256sum is designed to verify data integrity using the SHA-256 (SHA-2 family with a digest length of 256 bits).

$ date | sha256sum
9c8389ce6b87c8e401953fae7dc3a82b70042f8900638cf2c87550a5f15eb3d5  -

Generate strong password using sha1pass

sha1pass creates a SHA1 password hash. Without use any option in the command line, a random vector will be generated.

$ sha1pass
$4$sP0lvTtx$vWtERzFUpybYaV3zFh+wmJDQPUs$

Using sha1pass with the password option, the passed word is emedded in the hash string.

$ sha1pass password ChangeMe
$4$ChangeMe$/TsBdl4r0CJkvisl2emiaRyzkVU$

Create random password using /dev/urandom

Using /dev/urandom, the special character files /dev/random and /dev/urandom provide an interface to the kernel random number generator. The file /dev/random has the major device number 1 and the minor device number 8. The file /dev/urandom has the major device number 1 and the minor device number 9.

$ cat /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c 16
fuIA9aVtGhmlVs0R

quote using “head -c 16” to print the first 16 bytes.

Enable systemd on Debian 11 in WSL 2

Enable systemd on Debian 11 in WSL 2 to run as default Init-System. This guide will show how to enable systemd using services like mariadb and apache2 or docker and many others to work during a WSL session. This was tested on Windows 11 Build 22621, running Debian GNU/Linux 11 (bullseye) in WSL 2.

What is systemd?

systemd is a collection of programs, daemons, and libraries for Linux operating systems. Its central part is the systemd init process, which serves as the first process for starting, monitoring and terminating other processes.

Enable systemd on Debian in WSL 2

$ sudo vi /etc/wsl.conf

quote you can of course choose your favorite editor, for example instead of vi maybe nano is your editor of choice.

Edit the content below in the wsl.conf file.

[boot]
systemd=true

Next reboot the Debian in WSL session.

$ sudo reboot

you can also run the following command to terminate the Debian in the windows command prompt or in the powsershell.

C:\> wsl -t debian

where debian is the name of the wsl instance, replace it with your name.

to launch the debian use systemd in WSL ran the following command.

C:\> wsl.exe ~ -d Debian

the current status of wsl can be checked as follows.

C:\> wsl -l -v

the meaning of the parapeters are:
-l = Lists distributions
-v = Displays detailed information about all distributions

Now let’s see the status with show runtime status of units.

$ sudo systemctl status

Conclusion

In this guide, I’ll show you how to easily enable systemd on Debian to run as the default Init-System on WSL 2. This allows services like docker and apache2 or mariadb and many others to run during a WSL session. This was tested on Windows 11 Build 22621 running Debian GNU/Linux 11 (Bullseye) in WSL 2.

quote I found out that when Ubuntu is deployed in WSL 2, systemd is automatically enabled as the default init system. This allows like mariadb or docker and others services running in the Ubuntu WSL session.

a few more thoughts on systemd

The main criticism of systemd is its versatility. It violates the Unix philosophy of doing only one task, but doing it as well as possible. Systemd is also overly complex and error-prone. It is also criticized for having Google’s DNS and NTP server hard-coded as a fallback.

Debian systemd in WSL

The first processes start when booting, and Systemd already has a finger in the pie here in several ways. On the one hand, by controlling and organizing the entire boot process, on the other hand, by providing information later on how the started processes are doing.

systemd or System-V-Init

You have to decide for yourself whether you want to use systemd or the previous System-V-Init-Systems, but it’s useful to be able to choose one or the other and change it again at any time.

quote You might also be interested in these related post here.