OS X Password Generator in BASH

How do I generate random passwords on the command line using the terminal we have 2 options installing pwgen or add Bash function to create random password

Install pwgen (use Homebrew)

$ brew install pwgen

Add the following to your ~/.bash_profile

genpasswd() {
local l=$1
[ “$l” == “” ] && l=16
LC_ALL=C tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs

Reload your profile

$ source ~/.bash_profile

Run it

$ genpasswd 15
We aslo can defind password length like genpasswd 20 any number of choice

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: