Boost Your Security: Create a Custom Alias for Generating Strong Passwords in Terminal

ยท

1 min read

I will show you how I created an alias using the shell to generate a 24-character password in the next way x8-x8-x8.

I did it for macOS, but it should also work on Linux.

To do this, we will edit our terminal configuration file:

vi ~/.zshrc # commonly on macOS
# or 
vi ~/.bahsrc # commonly on linux

then copy and paste the next code at the end of the file and save:

# ...
function pwgen() {
    PWGEN=$(LC_CTYPE=C tr -dc 'A-Za-z0-9!@#$%&*' < /dev/urandom | head -c 26 | sed 's/\(........\)\(........\)\(........\)/\1-\2-\3/')
    #echo "$PWGEN" | pbcopy # optional - uncomment if u're using macOS for auto copy.
    echo "$PWGEN" | less
    unset PWGEN
}

alias pwgen='pwgen' # optional - you can change the alias name if you want.

now restart your terminal or open a new tab and try typing:

pwgen

and voilร !, copy your new password and press "q" for exit.

I hope this help you to create secure passwords easily! :)

ย