Introduction

passgen is a command-line application, so, you use it by sending commands to the shell program of your operational system. The simplest use of passgen, is to just give the program name, like in the example below:

terminal$ passgen
AWlooZVZkR

By default, passgen will generate a password with 10 characters. The characters included in your password, will depend on the chosen character set. You can change the behaviour of passgen, by using one (or many) of the available options. In summary, passgen supports the following command-line options:

  • -l or --length: define the length of your password (default to 10). This option expects a integer as argument;
  • -p or --number-of-passwords: the number of passwords to be generated (default to 1). This option expects a integer as argument;
  • -u or --no-upper-case-letters: exclude the Basic-Latin upper case letters from the character set;
  • -o or --no-lower-case-letters: exclude the Basic-Latin lower case letters from the character set;
  • -s or --special-chars: include special characters (e.g. $, %, #, @ etc.) in the character set;
  • -n or --numbers: include numbers (e.g. 0, 1, 2, etc.) in the character set;
  • -v or --version: prints the current version of the passgen program;
  • -h or --help: prints the help documentation;

Changing the length of the password

The length of the password is defined by the PASSWORD_LENGTH global variable. By default, this variable is set to 10, however, you can set it to whatever value you want, by using the -l option.

With this option, you can specify the exact number of characters you want in the resulting password. This options expects that you provide a integer argument, like in the example below, where we produce a 35 characters long password:

terminal$ passgen -l 35
AWlooZVZkRAKZOeydPIahrdueDDakizdtwv

If you prefer, you can use the long version of the option too, with --length:

terminal$ passgen --length 5
NhgcG

Changing the used character set

By default, passgen uses a combination of lower and upper case Basic-Latin letters (i.e. “A-Z” and “a-z”) to build your password. But you can use the available command-line options to change this character set, in order to produce passwords with different kinds of characters.

Including numbers

You can include numbers (i.e. “0-9”) in the character set, by including the -n option, like this:

terminal$ passgen -n -l 25
HvQ8aWCi6bPM8TfrKFLlJez04

Or, the long version of the option:

terminal$ passgen --numbers -l 25
HvQ8aWCi6bPM8TfrKFLlJez04

Including special characters

You can include special characters (e.g. “!”, “@”, “#”, etc.) in the character set, by including the -s option, like this:

terminal$ passgen -s -l 25
G^|TM$>Epa"a./}`IP/;#+gOz

Or, the long version of the option:

terminal$ passgen --special-chars
G^|TM$>Epa

Excluding lower and upper case Basic-Latin letters

You can not only include specific set of characters, but, you can also exclude them. By default, passgen starts with a set of characters containing the lower and upper case Basic-Latin letters, however, you can exclude them with the -o and -u options (or its longer versions: --no-lower-case-letters and --no-upper-case-letters).

terminal$ passgen -o
MZYDVTDWUE
terminal$ passgen -u
mzydvtdwue

Be careful to not remove all characters from the character set. In other words, if you remove the upper and lower case letters at the same time, and, not provide any set of characters to replace the void created, the program will issue an error warning about this mistake:

terminal$ passgen -o -u
With the arguments you gave at the command line, all character set flags are set to false! As a result, the program does not have a character set to generate your password! 
terminate called without an active exception

Producing “numbers-only” passwords

As an example, you can produce a “numbers-only” password, by passing a character set composed only of numbers to passgen. You can do this, by excluding the lower and upper case Basic-Latin letters, and, including the numbers with options -o, -u and -n:

terminal$ passgen -o -u -n
5310110841

Producing “special-chars-only” passwords

You could use the same resource of removing characters with -o and -u options, in order to produce a “special-chars-only” password, like this:

terminal$ passgen -o -u -s
$>/[$_#(!>

Producing multiple passwords

By default, passgen will generate a single password. However, you can produce multiple password at the same time, by using the -p option (or its long version --number-of-passwords). This option expects a integer argument like the -l option. In the following example, we are generating 6 different passwords with a single command:

terminal$ passgen -p 6
KnrFpCIBdp
vWMpJekJsF
KcfMTpPqFC
OkQNDlFZWp
JDkhdZzaBe
mtoejZINTV

Is important to highlight that, the options that you pass to passgen are disseminated to all of the generated passwords. In other words, if you use the option -p with the value of 10, and, the -l option with the value of 15, passgen will produce 10 different passwords that are 15 characters long:

terminal$ passgen -p 10 -l 15
bVFQKhYgARxUylK
rmONoEEQKwpSTTS
xarJOFzZUwUgPYB
aUCfLXNPTHGJtFV
TJFFFCLTQgjPkKC
FVyaFMRDsGmWXkf
ekJsFKnrFpCIBdp
KcfMTpPqFCvWMpJ
ZzaBeOkQNDlFZWp
mtoejZINTVJDkhd

This also means that passgen will use the same character set you built with the command-line options, to generate all of the different passwords. For example, if you use the options -n and -o like in the example below, passgen will generate 4 different passwords that have a combination of numbers and upper case Basic-Latin letters:

terminal$ passgen -p 4 -n -o
VOQ6H3BN9X
7MPWFCB82I
534FW142NH
3ZF9ED1OJ0