HOW TO: Random password generator on Ubuntu and other Linux systems

by Soddengecko @ 20:25   All | Code | Linux / Unix   Permalink

Recently I had need to generate random passwords. I did not want to make a script for it and I certainly did not want any applications to do the tasks. Here is the command line argument for such a task:


</dev/urandom tr -dc A-Za-z0-9_ | head -c8


Note that the ‘tr’ strips out everything except characters in the ranges (alphanumeric, mixed case and underscores). This is a nice approach as piping to head means the minimum number of bytes required to generate a password of appropriate length are taken from /dev/urandom vs other methods which take more than you should need but still have a chance of not having obtained enough random data to generate a password of the required length. You can change the parameter to head to get passwords of any length.

NOTE: I have only run this command on Ubuntu, its possible it works on other Linux systems but I have not checked.

Do you want to leave a reply?


XHTML: You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



Contact