ãã¹ã¯ã¼ãè¨å®ã®ã¡ãããã¿
ä»æ¥ã¯ãã¹ã¯ã¼ãè¨å®ã®ã¡ãããã¿ã§ã
ãã®1ï¼mkpasswdã使ã£ã¦ã©ã³ãã ãªãã¹ã¯ã¼ããçæãã
ãã¹ã¯ã¼ããèããã®ã¯çµæ§é¢åãªãã®ã§ãã
mkpasswdã使ãã¨ãã¾ãèããã«ãã¹ã¯ã¼ããçæã§ãã¾ãã
ããmkpasswdãããªããã°ãexpectããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ã
以ä¸ãªãã·ã§ã³ã
-l ãªãã·ã§ã³ã§ãã¹ã¯ã¼ãé·ï¼ããã©ã«ã9æåï¼
-d ãªãã·ã§ã³ã§ãã¹ã¯ã¼ãã«å«ã¾ããæ°åã®æ°ï¼ããã©ã«ã2æåï¼
-s ãªãã·ã§ã³ã§ãã¹ã¯ã¼ãã«å«ã¾ããè¨å·ã®æ°ï¼ããã©ã«ã1æåï¼
-c ãªãã·ã§ã³ã§ãã¹ã¯ã¼ãã«å«ã¾ããã¢ã«ãã¡ãããå°æåã®æ°ï¼ããã©ã«ã2æåï¼
-C ãªãã·ã§ã³ã§ãã¹ã¯ã¼ãã«å«ã¾ããã¢ã«ãã¡ããã大æåã®æ°ï¼ããã©ã«ã2æåï¼
â»è©³ç´°ã¯ man mkpasswdã§ã
ãã®2ï¼ã·ã§ã«ã¹ã¯ãªããããpasswdã使ã£ã¦ãã¹ã¯ã¼ããè¨å®ãã
passwd ã³ãã³ãã« --stdin ãªãã·ã§ã³ãä»ããã¨æ¨æºå
¥åãèªã¿è¾¼ããã®ã§ã
ãã¤ãã使ã£ã¦ãã¹ã¯ã¼ããè¨å®ãããã¨ãã§ãã¾ãã
ãããªæãã«ã
# echo "test" | passwd --stdin testuser Changing password for user testuser. passwd: all authentication tokens updated successfully.
ããã使ãã°ã·ã§ã«ã¹ã¯ãªããããã§ãOKã
ãã¾ãï¼ã¦ã¼ã¶ã¼ãã¾ã¨ãã¦ä½æããã¹ã¯ãªãããæ¸ãã¦ã¿ã
ä¸ã®TIPS使ã£ã¦ãã©ã³ãã ãªåæãã¹ã¯ã¼ãè¨å®ããªãã
ã¾ã¨ãã¦ã¦ã¼ã¶ã¼ãä½æããã¹ã¯ãªãããæ¸ãã¦ã¿ã¾ããã
ãuser_list.txtãã«ä½æãããã¦ã¼ã¶ã¼ã®æ
å ±ãè¨å®ã
å·¦ããé ã«ã¦ã¼ã¶ã¼å,uid,gid,ãã¼ã ãã£ã¬ã¯ããª,ã·ã§ã«ã
ãããªæãã
user1,2000,2000,/home/user1,/bin/bash user2,2001,2001,/home/user2,/bin/bash user3,2002,2002,/home/user3,/bin/bash user4,2003,2003,/home/user4,/bin/bash user5,2004,2004,/home/user5,/bin/bash
ã§ãã¹ã¯ãªããã®æ¬ä½ã§ãã
ãã¹ã¯ã¼ãé·ã8æåãè¨å·ãªããå¾ã¯ããã©ã«ãã®ã«ã¼ã«ã§ãã¹ã¯ã¼ããèªåçæã
#!/bin/sh USER_LIST="/home/hogehoge/user_list.txt" USER_PASS="/home/hogehoge/user_pass.txt" MKPASSWD="mkpasswd -l 8 -s 0" while read LINE do USER_NAME=`echo ${LINE} | cut -d, -f 1` USER_UID=`echo ${LINE} | cut -d, -f 2` USER_GID=`echo ${LINE} | cut -d, -f 3` USER_HOME=`echo ${LINE} | cut -d, -f 4` USER_SHELL=`echo ${LINE} | cut -d, -f 5` FIRST_PASS=`${MKPASSWD}` groupadd -g ${USER_GID} ${USER_NAME} useradd -u ${USER_UID} -g ${USER_GID} -d ${USER_HOME} -s ${USER_SHELL} ${USER_NAME} echo "${FIRST_PASS}" | passwd --stdin ${USER_NAME} echo "${USER_NAME},${FIRST_PASS}" >> ${USER_PASS} done < ${USER_LIST}
å®è¡ããã¨ããuser_pass.txtãã«è¨å®ãããã¹ã¯ã¼ããã¦ã¼ã¶ã¼åã¨å
±ã«åºåã
å·¦ããé ã«ã¦ã¼ã¶ã¼å,ãã¹ã¯ã¼ãã
ãããªæãã
user1,76lJNzin user2,9xq9PFpl user3,3vaiNTi4 user4,4uUIllf5 user5,isqYF42c
ãã¹ã¯ã¼ãã®ä¸è¦§ããã¡ã¤ã«ã«ãã¡ãã£ã¦ãã®ã¨ã
å®ã¯ã¨ã©ã¼å¦çãå
¨ç¶ãªãã®ã¯ãææ¬ã
ã¾ã ã¾ã æ¹è¯ããä½å°ãããããæ°ãåãããç´ãããã
ä»æ¥ã¯ãããªã¨ããã§ã