Create 10 system users in batch and set random number password
There are many ways for linux to generate random passwords, two of which are introduced here, one is the internal system variable ($RANDOM), and the other is to use openssl.
The internal system variable ($RANDOM) can directly echo to get a set of random numbers:
# echo $RANDOM30468
Get an 8-digit random number:
# echo $RANDOM | md5sum | cut-c 1-8393c839b
Use the openssl command to get a random number:
# openssl rand-base64 8qpIpWLYS6Yk =
Get an 8-digit random number:
# openssl rand-base64 8 | cut-c 1-8GPHYu+MU
Create 10 system users in batch and set the random number password script to:
# cat useradd.sh #! / bin/bashfor I in `seq-w 10` do pass= `echo $RANDOM | md5sum | cut-c 1-8` # when using random numbers as passwords, be sure to define variables, otherwise the generated password and the last recorded password are not uniform useradd user$i & & echo $password | passwd-stdin user$i echo-e "user:user$i\ t pass:$pass" > > / tmp/user.logdone