How to create Random password quickly in Linux?

Some times when creating bulk users, admins are forced to create complex passwords. But how to do it? How many you can set manually? Let me put it in this way. For one or two users we can think for a random password and assign to them. But if it’s 100 users? Naaa.. I cannot think for 100 passwds.

So leave this job to Linux to create random passwords. We can use below command to generate random passwords

< /dev/urandom tr -dc A-Na-n1-9_ | head -c8

This will just generate random 8 lenght password

For example :
See just typing the above command will generate a random password

root@ps6061:~# < /dev/urandom tr -dc A-Na-n1-9_ | head -c8


root@ps6061:~# < /dev/urandom tr -dc A-Na-n1-9_ | head -c8


root@ps6061:~# < /dev/urandom tr -dc A-Na-n1-9_ | head -c8


root@ps6061:~# < /dev/urandom tr -dc A-Na-n1-9_ | head -c8


root@ps6061:~# < /dev/urandom tr -dc A-Na-n1-9_ | head -c8


root@ps6061:~# < /dev/urandom tr -dc A-Na-n1-9_  | head -c8



Here is a script automate entire 20 user account creation.
#Author:Surendra Kumar Anne
#Purpose:To automate user creation
mkdir -p /home/admin/useraccounts
for (( i=0; i<=20; i++ ))


useradd user$i< /dev/urandom tr -dc A-Na-n1-9_ | head -c8 > /tmp/passwd.txt
cat /tmp/passwd.txt | passwd –stdin user$i
echo -e “Username:user$i” > /home/admin/useraccounts/user$i
echo -e “password:” >> /home/admin/useraccounts/user$i
cat /tmp/passwd.txt >> /home/admin/useraccounts/user$i
rm -rf /tmp/passwd.txt

Note : When password generating we have just created a password which will not contain o(small ooo), O(capital OO), 0(zero). This is to remove confusions for users. Some times user will get confusion when using these characters. If you want all the characters from a to z, A to Z, and 0-9 just use below code.

< /dev/urandom tr -dc A-Za-z0-9_ | head -c8