One line password generator

September 7, 2023    Article    160 words    1 min read

Quick guide for people who want to have a quick way to generate a random password without unlocking their favorite password manager. The only requirement (if you want clipboard copy) is xclip which can be installed on your distro from its package manager.

$ < /dev/urandom tr -dc "A-Za-z0-9_+$?=/\@!%&#()-" | head -c 32

The above command takes output (redirects) from /dev/random, passes it through tr by filtering all characters except the ones explicitly defined and cuts the resulted string after 32 characters. If you want more/less than 32 characters, adjust that part.

To copy the resulting string to clipboard:

$ /bin/sh -c '< /dev/urandom tr -dc "A-Za-z0-9_+$?=/\@!%&#()-" | head -c 32 | xclip -sel clip'

You can manually configure a menu item for Gnome/Xfce applications menu by copying this snippet of code to ~/.local/share/applications/passgen.desktop:

[Desktop Entry]
Name=Random password generator
Comment=Random password generator
Exec=/bin/sh -c '< /dev/urandom tr -dc "A-Za-z0-9_+$?=/\@!%&#()-" | head -c 32 | xclip -sel clip'