I’m frequently required to quickly get a hold of a random password. I’m either resetting password for a client or I’m testing something and I need a throwaway set of credentials. There are many ways to generate a random password (using DuckDuckGo, online password generator, password manager, etc.), but in terms of speed and convenience, nothing beats my old, trusted shell one-liner in the menu launcher. Just one click and boom - a random password is ready in my clipboard!
The shell one-liner in question is pretty simple. The only requirement is that you have xclip installed. This nifty little clipboard tool is packaged for all major GNU/Linux distributions.
/bin/sh -c '< /dev/urandom tr -dc "A-Za-z0-9_+$?=/\@!%&#()-" | head -c 20 | xclip -sel clip'
The above command redirects output from
/dev/urandom, passes it over through
tr to filter out all characters except the ones that are explicitly defined (i.e. alphanumeric plus some special characters), chops randomly generated string at 20th character and stores the password in the clipboard.
Instead of executing this one-liner every time you need a random password, you can configure a keyboard shortcut that triggers this command or you can create a menu launcher.
If you use Gnome, you can create a custom menu launcher using Alacarte, MenuLibre, or similar menu editor. Or you can manually configure menu item by saving the following snippet to
I’m not a KDE user, but I suppose you can use KMenuEdit to create a custom menu entry.