Usage
How to use the passgen command-line tool: presets, patterns, and the most useful flags.
There are two ways of using passgen: with a preset, or with a pattern.
Presets
Presets are named patterns. Passgen comes with some useful ones built in, and you
can define your own. Use --list to see every preset Passgen knows about, along
with its pattern:
$ passgen --list
preset apple1 ([a-zA-Z0-9]{3}-){3}[a-zA-Z0-9]{3}
preset apple2 ([a-zA-Z0-9]{6}-){2}[a-zA-Z0-9]{6}
preset edge [A-Za-f0-9:_\-]{15}
preset firefox [a-zA-Z0-9]{15}
...
preset uuid [0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}
To use one, pass its name to --preset:
$ passgen --preset apple2
L2wjZr-vEBpjz-v2J5br
The Presets page lists all of the built-in presets.
Patterns
A pattern describes the exact shape of the sequence you want. This is useful when none of the presets fit. The syntax is inspired by regular expressions and is explained in full on the Syntax page. Here are two examples:
$ passgen abc
abc
$ passgen '[a-z]{12}'
ybvhtqsielig
Everything below works with both presets and patterns. Most flags have a long
form, such as --amount, and a short form, such as -a.
Amount
By default, Passgen generates a single sequence. Use --amount to generate
several at once:
$ passgen --amount 5 '[a-z]{8}'
cnjeinds
mbwpqytl
zadpyddw
okjxixux
olyvkviz
Entropy
Entropy measures how much randomness went into a sequence, and so how hard it is
to guess. Higher is better. With --entropy, Passgen prints the entropy of every
sequence it generates:
$ passgen -e '[a-z]{8}'
entropy: 37.60 bits
grxrmizc
$ passgen -e '[a-zA-Z0-9]{18}'
entropy: 107.18 bits
llSPscUSa8BYEkUQXQ
The entropy is printed to standard error, so it does not end up in the output when you pipe it or capture it in a script.
Aim for passphrases with more than 100 bits. The Entropy page explains what the number means.
Wordlists
Completely random characters are hard to remember, especially if you use a different passphrase for every site. A common trick is to use random words from a dictionary instead.
Use --wordlist NAME:PATH to load a wordlist, with one word per line, and give it
a name. You can then refer to it in the pattern with \w{NAME}, which is replaced
with a random word from the list:
$ passgen --wordlist english:/usr/share/dict/words '(\w{english}-){3}\w{english}'
decreeing-soreheads-wheresoever-encipherer
You can load several wordlists by repeating the flag. Wordlists can be in any language, since Passgen fully supports Unicode. To keep a wordlist around, define it in the configuration.
Markov chains
Instead of picking real words, Passgen can learn from a wordlist how words in that
language are built, by looking at how often different sequences of letters appear.
It stores this in a Markov chain and
uses it to make up words that do not exist, but are close enough to real words to
be pronounceable. Use \m{NAME} for this:
$ passgen --wordlist english:/usr/share/dict/words '(\m{english}-){3}\m{english}'
laston-miscreprimithesis-phopsis-disreleastically
Made-up words carry more entropy than dictionary words, so you need fewer of them
for the same strength. Their entropy varies from one passphrase to the next, so
generate them with --entropy. The Markov chains page explains
how they work, and how to choose the length of the chain.
JSON output
If you want to feed Passgen's output into other tools, use --json. For example,
you can post-process it with jq:
$ passgen -j -p apple1
[{"output":"OLS-Kas-WV4-J1W"}]
$ passgen -j -e -a 2 '[a-z]{19}' | jq
[
{
"output": "lfhaalsbjsclwdsgzey",
"entropy": 89.308355
},
{
"output": "rcdxixtzghhcaxbgbrh",
"entropy": 89.308355
}
]
For plain-text output, --null separates sequences with a NUL character instead
of a newline.
Configuration
Presets and wordlists that you use often can be defined in a configuration file, at
~/.config/passgen/config.toml:
[wordlists]
english = "/usr/share/dict/words"
[presets]
pin = '[0-9]{6}'
They can then be used like the built-in ones:
$ passgen -p pin
977707
$ passgen '\w{english}-\w{english}'
goban-withdrawment
The Configuration page explains everything that can go into this file.
All flags
| Flag | Description |
|---|---|
-a, --amount N | Generate N sequences. |
-e, --entropy | Print the entropy of each sequence, in bits. |
-j, --json | Output as JSON. |
-z, --null | Separate sequences with NUL instead of a newline. |
-p, --preset NAME | Use the preset NAME. |
-P, --define-preset NAME:PATTERN | Define a preset. |
-l, --list | List the loaded presets. |
-w, --wordlist NAME:PATH | Load the wordlist at PATH as NAME. |
-c, --config PATH | Read this configuration file instead of the usual ones. Can be repeated. |
-r, --random SOURCE | Use a different source of randomness. |
--offset N | Generate the Nth sequence of a deterministic source of randomness, counting from 0. |
-S, --steps N | Limit how many steps generating may take. The default is 1000000. |
-v, --version | Show the version. |
-h, --help | Show the help text. |
These flags are for master-passphrase mode:
| Flag | Description |
|---|---|
-m, --master NAME | Use the master passphrase NAME from the configuration. Passgen asks for the passphrase. |
-d, --domain DOMAIN | What the passphrase is for, typically the domain of a website. |
-u, --user USER | Who the passphrase is for, typically your login on the website. |
--master-setup [NAME] | Set up a master passphrase, and print what to add to the configuration. |
--master-level LEVEL | With --master-setup, set the level from 1 to 3 without asking. |
--master-seed | With --master-setup, generate a seed without asking. |
--master-version VERSION | With --master-setup, set how keys are derived. Only 1 exists so far. |
Passgen also comes with a manual page: man passgen.