Showing posts with label Secure Password. Show all posts
Showing posts with label Secure Password. Show all posts

Monday, July 13, 2009

Shell: Linux Password Generator

A simple bash function to generate secure passwords with standard Unix programs:

function mkpw() { head /dev/urandom | uuencode -m - | sed -n 2p | cut -c1-${1:-8}; }
Add that to your ~/.bashrc file. The password length can be specified as an argument (defaults to 8).
Example usage:

$ mkpw
B5PcCWC3
$ mkpw 10
V8T7ZrTQuN
On Ubuntu, the uuencode program is in the sharutils package. Alternatively, you could replace uuencode with md5sum or sha1sum, which would restrict the passwords to hex digits (and which would therefore make them appropriate for WEP keys and the like):

function mkpw_md5() { head /dev/urandom | md5sum | cut -c1-${1:-8}; }
function mkpw_sha1() { head /dev/urandom | sha1sum | cut -c1-${1:-8}; }