Simple Random Password Generator – Command Line (LINUX)

A brute-force attack is when all possible keys are checked against encrypted data until the right key is found. Brute-force attacks are extremely costly from a resource and time perspective because the attacker is exploiting vulnerabilities in the encryption by taking advantage of key length and simplicity of the key.

A password is often based on dictionary words meaning the total space an attacker would have to test would be all words in a matching dictionary making the guessing scope significantly smaller than a password using random characters.

Best practice to mitigate brute-force attacks is using long and complicated keys as well as timeouts after a number of attempts and other methods to add more security factors.

Use the following command to generate a random password of any choice(length):

Command: tr -dc A-Za-z0-9 < /dev/urandom | head -c 8 | xargs

You can even create a bash function by editing the /root/.bashrc file and add the following code at the end of the file.

Code:

# Random password generator
genpasswd() {
tr -dc A-Za-z0-9 < /dev/urandom | head -c ${1:-8} | xargs
}

Then use “genpasswd” command to generate a random password of your choice.

For Example, if you want to generate a random password of 15 digits, then the command will be “genpasswd 15“.