Invoke a command to generate a random password of length n

Here’s one way to generate a -good- random password of length n invoking a simple command in the terminal, like so for instance: psswd 30 , where 30 stands for a 30 characters long password.

In order to do so, you need to edit ~/.bashrc or ~/.zshrc depending whether your shell is bash or zsh, and append psswd() { LC_ALL=C tr -dc ‘a-zA-Z0-9-!”@/#$%^&*()_+~’ < /dev/urandom | head -c “$1”;echo ;} to the file, then save it and restart the terminal if you had any opened. Now typing psswd n where n stands for the password length will generate a random password that may contain alphanumerical characters as well as the special characters displayed between the 2 ‘ signs. You can of course modify the characters used to generate the passwords and the function “psswd()” to any of your like.

To finish this blog entry, here’s an example of a 100 characters long password generated by the above command: WTx@X#!O$q!b!IDu+M7gvMVTv-^QK8O-(Y”NMO&%)P1Z4)h2K03uwf(Yc^~h76yi2&CaFE$$R3L&c$XKvnBsojJ6MBgW/S$q-_&o.

Have fun.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s