When installing a new server or just creating an online account is common to need a secure password. You can use a password generator to create a secure password, but you can also use the command line to generate a secure password.
openssl rand -base64 32 | pbcopy
This command will generate a secure password and copy it to your clipboard. You can also use the
tr command to remove the new line character.
openssl rand -base64 32 | tr -d '\n' | pbcopy
In case you want to save it to a file, you can use the
openssl rand -base64 32 | tr -d '\n' | tee -a ~/password.txt
All the commands above will generate a 32 character password. You can change the number to generate a different length password. Also I’m using
-base64 to generate a password with letters, numbers and special characters (plus and equal sign). You can use
-hex to generate a password with only letters and numbers.