Pwgen Command: Random Password Generator for Linux
In this tutorial, we’ll look at the pwgen
command—a simple yet powerful tool for generating strong, random passwords in Linux.
Install Pwgen
Pwgen command isn’t installed by default. On Ubuntu or Debian-based systems, you can install it with:
sudo apt update
sudo apt install pwgen
For Fedora, CentOS, or Red Hat-based systems, use the following command to install pwgen
:
sudo dnf install pwgen
Generate Random Passwords
After installing pwgen
, you can start generating passwords right away. Just type: pwgen
:
pwgen
The command will generate a list of secure, easy-to-remember 8-character passwords.
If you need longer passwords, just specify the length as an argument. For example following command will generate a list of 16-character passwords:
pwgen 16
To limit the number of passwords generated, add the desired number as the second argument. For example, the following command will generate one 32 character password:
pwgen 32 1
Command Options
You can use the following command options to make passwords stronger.
-s
: Generate completely random not-easy to remember passwords-c
: Include at least one uppercase letter-n
: Include at least one number-y
: Include symbols
Examples: Make Passwords More Secure and Strong
Generate a list of completely random 8 character passwords:
pwgen 8 -s
Generate a 16 character password, with at least one capital letter and a number:
pwgen 16 1 -cn
Generate a 32 character password with capital letters, numbers and symbols:
pwgen 32 1 -cny
You can save the generated passwords to a file for later use. The following command generates ten 16-character passwords and saves them in a text file called password.txt:
pwgen 16 10 > password.txt
To view the all command option for pwgen
command type pwgen -h
.