標籤:密碼 使用者 帳號 password
要求:大量建立10個系統帳號oldboy01-oldboy10,並設定產生密碼(密碼不同).
實現指令碼:
#!/bin/bash#Question3for i in $(seq -w 10)do useradd -s /bin/bash oldboy$i echo "password$i" | md5sum | tee -a passwd.txt | passwd --stdin oldboy$idone
指令碼執行效果:
[[email protected] q4]# sh q4.shChanging password for user oldboy01.passwd: all authentication tokens updated successfully.Changing password for user oldboy02.passwd: all authentication tokens updated successfully.Changing password for user oldboy03.passwd: all authentication tokens updated successfully.Changing password for user oldboy04.passwd: all authentication tokens updated successfully.Changing password for user oldboy05.passwd: all authentication tokens updated successfully.Changing password for user oldboy06.passwd: all authentication tokens updated successfully.Changing password for user oldboy07.passwd: all authentication tokens updated successfully.Changing password for user oldboy08.passwd: all authentication tokens updated successfully.Changing password for user oldboy09.passwd: all authentication tokens updated successfully.Changing password for user oldboy10.passwd: all authentication tokens updated successfully.查看passwd檔案:[[email protected] q4]# tail -n 10 /etc/passwdoldboy01:x:501:501::/home/oldboy01:/bin/basholdboy02:x:502:502::/home/oldboy02:/bin/basholdboy03:x:503:503::/home/oldboy03:/bin/basholdboy04:x:504:504::/home/oldboy04:/bin/basholdboy05:x:505:505::/home/oldboy05:/bin/basholdboy06:x:506:506::/home/oldboy06:/bin/basholdboy07:x:507:507::/home/oldboy07:/bin/basholdboy08:x:508:508::/home/oldboy08:/bin/basholdboy09:x:509:509::/home/oldboy09:/bin/basholdboy10:x:510:510::/home/oldboy10:/bin/bash
帳號成功建立。然後看一下密碼檔案:
[[email protected] q4]# lspasswd.txt q4.sh[[email protected] q4]# cat passwd.txt#MD5機密後的密碼10b222970537b97919db36ec757370d2 -f1f16683f3e0208131b46d37a79c8921 -32a3571fa12b39266a58d42234836839 -10b222970537b97919db36ec757370d2 -f1f16683f3e0208131b46d37a79c8921 -32a3571fa12b39266a58d42234836839 -978a60e3ebbb2dd56aa5f821d7f42a2b -cdffb1b0971ab2a3befc18c43d3ca5be -4679834a98e77dd2cec854b51de6d886 -ad8e8436435f93f6a7b295418889edff -f46c891cad3974fc64b7133911404c2a -ebde6449998d7c84ccb23725ecac782b -6c60d92e5b9757ce16c8e238174a6cac -5147eebead1aee9cbe761ec89b1101f1 -16a383252c3a264b3d977592ce8cf8ee -446174d0862f8f830ef4c54bdcf73d82 -166335a86348834ffd4d79cd5a73867b -
要求2:大量建立10個系統帳號oldboy01-oldboy10,並隨機設定密碼(密碼為8位字元).
基於上面指令碼略作修改:
#!/bin/bash#Question4for i in $(seq -w 10)do useradd -s /bin/bash oldboy$i echo "password$i" | md5sum |cut -c-8 | tee -a passwd.txt | passwd --stdin oldboy$idone
執行效果:
[[email protected] q4]# sh q4.shChanging password for user oldboy01.passwd: all authentication tokens updated successfully.Changing password for user oldboy02.passwd: all authentication tokens updated successfully.Changing password for user oldboy03.passwd: all authentication tokens updated successfully.Changing password for user oldboy04.passwd: all authentication tokens updated successfully.Changing password for user oldboy05.passwd: all authentication tokens updated successfully.Changing password for user oldboy06.passwd: all authentication tokens updated successfully.Changing password for user oldboy07.passwd: all authentication tokens updated successfully.Changing password for user oldboy08.passwd: all authentication tokens updated successfully.Changing password for user oldboy09.passwd: all authentication tokens updated successfully.Changing password for user oldboy10.passwd: all authentication tokens updated successfully.#看一下密碼檔案#tee命令中由於使用-a,所以是追加而不是覆蓋[[email protected] q4]# cat passwd.txt10b222970537b97919db36ec757370d2 -f1f16683f3e0208131b46d37a79c8921 -32a3571fa12b39266a58d42234836839 -10b222970537b97919db36ec757370d2 -f1f16683f3e0208131b46d37a79c8921 -32a3571fa12b39266a58d42234836839 -978a60e3ebbb2dd56aa5f821d7f42a2b -cdffb1b0971ab2a3befc18c43d3ca5be -4679834a98e77dd2cec854b51de6d886 -ad8e8436435f93f6a7b295418889edff -f46c891cad3974fc64b7133911404c2a -ebde6449998d7c84ccb23725ecac782b -6c60d92e5b9757ce16c8e238174a6cac -5147eebead1aee9cbe761ec89b1101f1 -16a383252c3a264b3d977592ce8cf8ee -446174d0862f8f830ef4c54bdcf73d82 -166335a86348834ffd4d79cd5a73867b -cdffb1b04679834aad8e8436f46c891cebde64496c60d92e5147eebe16a38325446174d0166335a8
上面少了隨機的過程:
大量刪除剛才建立的使用者:
#!/bin/bash#del_user.shfor i in `seq -w 10`do userdel -r oldboy$idone
隨機產生密碼的指令碼:
#!/bin/bash#Question4for i in $(seq -w 10)do useradd -s /bin/bash oldboy$i echo "$RANDOM" | md5sum |cut -c-8 | tee passwd.txt | passwd --stdin oldboy$idone
本文出自 “史振寧的技術部落格” 部落格,請務必保留此出處http://magic3.blog.51cto.com/1146917/1431581