Add users in bulk and set a random password to save the added user's name and password to a file.
[Email protected] scripts]#CatUser.SH #!/bin/SH forIinch`seq-W Ten` DoPass=$(Echo "' Date ' $RANDOM"|md5sum|Cut-C1-8) //Take the random number method is the date result and random number concatenation and calculates the MD5 value to take the first 8 bits useradd kg$iEcho "$pass"|passwd--stdin kg$iEcho-E"Kg$i\t$pass">>/tmp/Pass.txt Done[email protected] scripts]#seq-W Ten on GenevaGenevaGeneva to . - , theTen[email protected] scripts]#SHUser.SHChanging password foruser kg01.passwd: All authentication tokens updated successfully. changing password foruser kg02.passwd: All authentication tokens updated successfully. changing password foruser kg03.passwd: All authentication tokens updated successfully. changing password foruser kg04.passwd: All authentication tokens updated successfully. changing password foruser kg05.passwd: All authentication tokens updated successfully. changing password foruser kg06.passwd: All authentication tokens updated successfully. changing password foruser kg07.passwd: All authentication tokens updated successfully. changing password foruser kg08.passwd: All authentication tokens updated successfully. changing password foruser kg09.passwd: All authentication tokens updated successfully. changing password foruser kg10.passwd: All authentication tokens updated successfully. [Email protected] scripts]#Cat/tmp/pass.txt kg01 3577b000kg02 3ddefcfekg03 c1ec8c1ekg04 0bdcdafckg05 f172c380kg0699471166kg07 fbe82aebkg08 cad21c1ckg09 5f7cdc56kg10 b60958ad[[email protected] scripts]#Tail-Ten/etc/passwdkg01:x:504:504::/home/kg01:/bin/bashkg02:x:505:505::/home/kg02:/bin/bashkg03:x:506:506::/home/kg03:/bin/bashkg04:x:507:507::/home/kg04:/bin/bashkg05:x:508:508::/home/kg05:/bin/bashkg06:x:509:509::/home/kg06:/bin/bashkg07:x:510:510::/home/kg07:/bin/bashkg08:x:511:511::/home/kg08:/bin/bashkg09:x: +: +::/home/kg09:/bin/bashkg10:x:513:513::/home/kg10:/bin/Bash[[email protected] scripts]#
Several methods of taking random numbers in Linux:
[Email protected] scripts]#Echo$RANDOM10474[email protected] scripts]# OpenSSL rand-base648C8ZBCMMHLKC=[email protected] scripts]# OpenSSL rand-base646Bsazww8v[[email protected] scripts]# OpenSSL rand-base643+S4k[[email protected] scripts]# OpenSSL rand-base644Daneuw==[email protected] scripts]#Date+%s%N1448293383949936583[email protected] scripts]#Date+%s%N1448293385095579398[email protected] scripts]#Date+%s%N1448293386596694243[email protected] scripts]#Head/dev/urandom|cksum1336286598 1963[email protected] scripts]#Head/dev/urandom|cksum3913907857 2588[email protected] scripts]#Head/dev/urandom|cksum321627736 1498[email protected] scripts]#Cat/proc/sys/kernel/random/UUID b8238fed-be13-47ac-8e30-B86ea0f822ff[[email protected] scripts]#Cat/proc/sys/kernel/random/UUID 0bb0cb5d-157e-45f9-889a-0d6a93d3d328[[email protected] scripts]#Cat/proc/sys/kernel/random/UUID 526C2CB3-a335-4013-bf71-108e7517c4d9[[email protected] scripts]#
Using Shell to bulk add users