How to generate random password in Linux Shell

Scripting random password in shell 99 times1 answer1 follower
0
Mel Khamlichi 103 Rep. Avishek Kumar edited question

How to write shell scripts to generate random password of 10 characters? Is there any command to do it or will it need something complex like a shell script?

♥ Spread the love ♥
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
0
Avishek Kumar 449 Rep. Avishek Kumar edited answer

There are several ways to generate random password of any any desired characters in Linux.

  1. pwgen
  2. pwgen is a Linux command-line utility, that generates secure and human-memorable passwords of desired character of any number in one go. To generate 8 passwords of 10 digit, you may do

    Sample Output

    To make it even stronger, flag ‘-s’ can be used, that generates random and hard-to-remember password.

    Sample Output

    Optional

    You may generate username as well, randomly using command-line utility gpw. To generate 3 random usernames of 6 charcter, you may do

  3. openssl
  4. openssl is called as the swiss army of the cryptography. you can use openssl to generate random password like

    Sample Output

  5. $RANDOM
  6. $RANDOM is a built-in variable in BASH. You can generate random password something like

    Sample Output

    In case if you want to generate just numeric password

    Sample Output

  7. bash.generate.random.alphanumeric.string.sh
  8. The below script is written by ‘earthgecko’. You can get the latest version from here.

    Sample Output

    This script generates a random number of 32 characters. To generate a random password of 10 digits out of this script, you may do 2 things.

  • Edit the script and replace 32 by 10. Hence the script now looks something like
  • Sample Output

  • Don’t edit the script but pipe its output of 32 character with ‘cut’ Linux command to get 10 characters like
  • Sample Output

♥ Spread the love ♥
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
×

Login