How to use a command line random password generator PWGEN on Linux

The pwgen command in Linux is a powerful and flexible tool used for generating random passwords. It offers various options to customize the passwords according to different requirements, such as length, inclusion of symbols, avoidance of ambiguous characters, and more. This article will guide you through the usage of pwgen and demonstrate how to leverage its options to generate secure and tailored passwords for your needs.

In this tutorial you will learn:

  • How to generate passwords with pwgen
  • Different options available in pwgen
  • Examples of pwgen usage
How to use a command line random password generator PWGEN on Linux
How to use a command line random password generator PWGEN on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distribution
Software pwgen
Other None
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Using the pwgen Command in Linux

The pwgen command generates random, pronounceable passwords. It can be used directly from the terminal with various options to customize the output. Below are detailed examples showing how to use pwgen to generate passwords of different lengths, with or without symbols, and more.

  1. Generate passwords of default length (8 characters): This is the simplest usage of pwgen, generating one password with the default length.
    $ pwgen

    The output will be a single password of 8 characters, which is the default length for pwgen.

    Generate passwords of default length
    Generate passwords of default length
  2. Generate 5 passwords of default length (8 characters): Use this command to generate multiple passwords at once.
    $ pwgen 8 5

    This will generate 5 passwords, each 8 characters long.

  3. Generate a single password of 12 characters: You can specify the length of the password by providing a number.
    $ pwgen 12 1

    This command generates one password that is 12 characters long.

  4. Generate 10 passwords of 16 characters each: To generate multiple passwords of a specified length.
    $ pwgen 16 10

    This will output 10 passwords, each 16 characters long.

  5. Generate a single password of 12 characters without symbols: Use the -s option to generate secure, non-symbolic passwords.In the context of password generation, “symbols” refer to special characters that are not letters or digits. These characters can include punctuation marks and other typographic symbols.
    $ pwgen -s 12 1

    This command creates one password of 12 characters without including any symbols.

  6. Generate 5 passwords of 12 characters each including symbols: The -y option includes symbols in the password.
    $ pwgen -y 12 5

    This will generate 5 passwords of 12 characters each, including symbols.

  7. Generate a single password of 20 characters including capital letters: The -c option includes capital letters in the password.
    $ pwgen -c 20 1

    This command generates a single password of 20 characters that includes capital letters.

  8. Generate 3 passwords of 15 characters each including symbols and capital letters: Combining options for more complex passwords.
    $ pwgen -sc 15 3

    This command will generate 3 passwords, each 15 characters long, including both symbols and capital letters.

  9. Generate a single password of 14 characters avoiding ambiguous characters: The -B option avoids ambiguous characters like l, 1, O, 0.
    $ pwgen -B 14 1

    This command generates a 14-character password that avoids ambiguous characters.

  10. Generate a single password of 10 characters including at least one number: The -0 option ensures the inclusion of at least one number.
    $ pwgen -0 -n 10 1

    This command generates a 10-character password that includes at least one number. The -n option is added to ensure numerals are included.

  11. Generate 4 passwords of 8 characters each with numerals only: The -n option generates passwords with numerals only.
    $ pwgen -n 8 4

    This will generate 4 passwords, each 8 characters long, containing only numerals.

  12. Generate a single password of 8 characters with various requirements: Combining multiple options for a highly secure password.
    $ pwgen -ycs0 8 1

    This generates one 8-character password that includes symbols, capital letters, and at least one number.

  13. Generate 6 passwords of 12 characters each with symbols and excluding ambiguous characters: Combining options to meet specific criteria.
    $ pwgen -ysB 12 6

    This command will generate 6 passwords, each 12 characters long, including symbols and excluding ambiguous characters.

  14. Generate a single password of 15 characters with vowels: The -v option includes vowels to make the password more pronounceable.
    $ pwgen -v 15 1

    This command generates a single password of 15 characters that includes vowels, making it more pronounceable.

  15. Generate 2 passwords of 10 characters each, which are easier to remember: The -1 option generates passwords that are easier to remember.
    $ pwgen -1 10 2

    This generates 2 passwords, each 10 characters long, that are easier to remember.

Conclusion

The pwgen command is a versatile tool for generating random passwords in Linux. By understanding and utilizing the various options available, you can create passwords that meet specific security requirements, from simple and pronounceable passwords to complex and highly secure ones. This guide has provided a comprehensive overview of how to use pwgen, including detailed examples to help you get started.