cat brain | grep interesting >> blog

  • Archive
  • RSS

os x command line random password generator

If you want a quick little random password generator (uppercase, lowercase, and numbers) from the terminal in OS X you can add something like this to your .bashrc

randompass() {

        LANG=C

        local l=$1

        [ “$l” == “” ] && l=12

        tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs

}

It defaults to 12 characters but takes any numeric argument.  So usage to create a 21 character random password would be
randompass 21
Make sure to source .bashrc after you add that to give it a try.  If you haven’t already created .bashrc and .bash_profile on your Mac, do that first and then add in the following to .bash_profile
source ~/.bashrc
This will also work for any other *nix as well.
    • #os x
    • #nix
    • #cli
    • #weeee
  • 1 year ago
  • Comments
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Recent comments

Blog comments powered by Disqus
← Previous • Next →
My name's Josh and I'm a SysAdmin. I post stuff that I think will be helpful to others.

My opinions/posts on my blog and Twitter are my own and do not reflect the views of my current or former employer(s).

The Twitters

loading tweets…

  • RSS
  • Random
  • Archive
  • Mobile
Effector Theme by Pixel Union