|
1. Linux ÀÇ °æ¿ì
./adduser_sh USERNAME PASSWORD HOME_DIR
-------------- adduser_sh cut here ------------------
#!/bin/sh
CHK=
user=${1}
pass=${2}
home=${3}
[ -n "${home}" ] && home="-d ${home}"
adduser ${user} ${home}
CHK=$?
if [ $CHK -ne 0 ]; then
exit 1
fi
echo "${pass}" | passwd ${user} --stdin
CHK=$?
if [ $CHK -ne 0 ]; then
exit 1
fi
exit 0
-------------- adduser_sh cut here ------------------
2. Other OS ÀÇ °æ¿ì
Linux °¡ ¾Æ´Ò °æ¿ì¿¡´Â passwd ¿¡¼ --stdin ÀÌ Áö¿øÀÌ µÇÁö ¾ÊÀ¸
¹Ç·Î adduser ÀÇ -p ¿É¼ÇÀ» »ç¿ëÇØ¾ß ÇÑ´Ù. ¹°·Ð adduser ¿¡¼ -p ¿É¼Ç
ÀÌ Áö¿øµÇÁö ¾Ê´Â´Ù¸é »ç¿ëÇÒ ¼ö ¾ø´Ù.
¶ÇÇÑ, ÀÌ ¹æ¹ýÀ» »ç¿ëÇÒ °æ¿ì¿¡´Â password ¸¦ encoding ÇÑ °ªÀ» »ç¿ë
ÇØ¾ß ÇϹǷΠº°µµ ÀÇ utility °¡ ÇÊ¿äÇÏ´Ù.
2.1 apache °¡ ¼³Ä¡µÇ¾î ÀÖÀ» °æ¿ì
-------------- adduser_sh cut here ------------------
#!/bin/sh
# md5 ¾ÏȣȰ¡ Áö¿øÀÌ µÉ °æ¿ì.
# ¾ÈµÉ °æ¿ì¿¡´Â 0À¸·Î ¼³Á¤ÇÒ °Í.
# passwd ³ª shadow ÆÄÀÏ¿¡¼ ¾ÏÈ£ÈµÈ Æнº¿öµåÀÇ ±æÀÌ°¡
# 8°¡ À̸é 0À¸·Î ¼³Á¤ÇØ¾ß ÇÔ.
md5opt=1
CHK=
user=${1}
pass=${2}
home=${3}
[ -n "${home}" ] && home="-d ${home}"
if [ -n "${pass} ]; then
[ $md5opt -eq 1 ] && mdopt="-m"
pass=$(htpasswd $mdopt -n b {$user} | sed 's/.*://g')
pass="-p \"${pass}\""
fi
adduser ${user} ${home} {$pass}
CHK=$?
if [ $CHK -ne 0 ]; then
exit 1
fi
exit 0
-------------- adduser_sh cut here ------------------
2.1 apache °¡ ¼³Ä¡µÇ¾î ÀÖÁö ¾ÊÀ» °æ¿ì
ÀÌ °æ¿ì´Â ¾ÏÈ£È À¯Æ¿¸®Æ¼°¡ ÀÖ¾î¾ß ÇÑ´Ù. ÀÌ À¯Æ¿¸®Æ¼´Â
http://linux-sarang.net/board/?p=read&table=tip&no=10549
¿¡¼ ÆÛ¿Ô´Ù.
-------------genpass.c-------------------------------
#include
int
main(int argc, char *argv[])
{
char *cypher;
char *salt = argv[1];
char *key = argv[2];
cypher = crypt(key, salt);
printf("%s\n", cypher);
return 0;
}
-------------genpass.c-------------------------------
genpass.c ¶ó´Â ÆÄÀÏÀ» ¸¸µé¾î À§ÀÇ ³»¿ëÀ» ±âÀÔÇÑ´Ù. ´ÙÀ½
gcc -O2 -o genpass genpass.c
install -m 700 genpass /usr/local/sbin/genpass
°ú °°ÀÌ ¸í·ÉÀ» ½ÇÇàÇÑ´Ù.
±×¸®°í ¾Æ·¡¿Í °°ÀÌ ½ºÅ©¸³Æ®¸¦ ¸¸µé¾î »ç¿ëÇÏ¸é µÈ´Ù.
-------------- adduser_sh cut here ------------------
#!/bin/sh
CHK=
user=${1}
pass=${2}
home=${3}
[ -n "${home}" ] && home="-d ${home}"
if [ -n "${pass} ]; then
pass=$(/usr/local/sbin/genpass {$user} {$pass})
pass="-p \"${pass}\""
fi
adduser ${user} ${home} {$pass}
CHK=$?
if [ $CHK -ne 0 ]; then
exit 1
fi
exit 0
-------------- adduser_sh cut here ------------------ |