Linux generates random password/modify password

  

Linux generates random password method:

strings /dev/urandom |  Grep -o ‘[[:alnum:]]’ |  Head -n 30 |  Tr -d ‘n’; echo

Linux password change method:

passwd root

Then enter the new password twice

root can be replaced with Users who need to be modified

In addition to the above random password generation we have other methods

1. Use the mkpasswd command:

To use the mkpasswd command, you need to install the expect module in advance. CentOS is an example:

yum -y install expect

After installation, run mkpasswd directly to generate a random password. And the command has parameters, such as setting the minimum length of the generated random password, etc., look at the help to know.

2. Use the passwdgen command:

is roughly the same as mkpasswd. You need to install the passwdgen module beforehand:

yum -y install passwdgen

After installation, Run passwdgen directly to get a random password. The same passwdgen command also has parameters. You can refer to help.

Add some commands to generate random passwords

Here are ten examples of generating random passwords

1.SHA+date+base64, password length 32 date +%s |  Sha256sum |  Base64 |  Head -c 32 ; echo

2. Use urandom to filter out other symbols, leaving only letters and numbers, password length 32 < /dev/urandom tr -dc _A-Z-a-z-0-9 |  Head -c${1:-32};echo;

3. Use the random function of openssl openssl rand -base64 32

Another use of urandom, urandom+tr tr - Cd '[:alnum:]' < /dev/urandom |  Fold -w30 |  Head -n1

5. Use urandom plus character function strings /dev/urandom |  Grep -o ':alnum:' |  Head -n 30 |  Tr -d 'n'; echo

6. The simplest use of urandom < /dev/urandom tr -dc _A-Z-a-z-0-9 |  Head -c6

Another use of 7.urandom, urandom+dd dd if=/dev/urandom bs=1 count=32 2>/dev/null |  Base64 -w 0 |  Rev |  Cut -b 2- |  Rev

8. If you often use a one-handed password, you can refer to the following method to generate "left-hand password" /dev/urandom tr -dc '12345!@#$%qwertQWERTasdfgASDFGzxcvbZXCVB' |  Head -c8; echo ""

9.Use randpw plus urandom randpw(){ < /dev/urandom tr -dc _A-Z-a-z-0-9 |  Head -c${1:-16};echo;}

10. Finally, the most concise date |  Md5sum

Copyright © Windows knowledge All Rights Reserved