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
Eq7ZqEuiyHxscL
We aslo can defind password length like genpasswd 20 any number of choice
Leave a Reply