unix 계정 자동 생성

2012.04.15 10:08

엘카 조회 수:10727

참고 문서  

MySQL 작업은 포함하지 않았습니다.

# vi /bin/useradd.sh

#!/bin/bash

### 계정 홈 디렉토리 ###
home="/home" # 앞 슬래쉬 / 뒤는 생략
### httpd.conf 경로 ###
vhost="/usr/local/apache/conf/extra/httpd-vhosts.conf"
### apachectl ###
apachectl="/usr/local/apache/bin/apachectl"
### public_html  ###
www=public_html
### 이메일 ###
email="[email protected]"

hr="=====================================================\n"

### 선택 ###
#echo -e "$hr\n [1] 계정을 생성합니다.
# [2] VirtualHost에 추가합니다."


### 계정 입력 ###
echo -e "${hr}계정 명을 입력해주세요."
read id
echo -e "${hr}비밀번호를 입력해주세요."
read pw


### 입력한 정보가 맞습니까? ###
echo -e "${hr}계정 이름: $id
비밀번호: $pw
 입력하신 정보가 맞습니까? [y/N]:"
read check
if [ $check != "y" ] && [ $check != "Y" ];then
 exit
fi
adduser $id
echo "$pw" | passwd --stdin "$id"
echo -e "${hr}계정이 추가되었습니다."


### domain, public_html ###
echo -e "${hr}1. $home/$id/$www 디렉토리를 생성합니다.
2. 웹 디렉토리는 701 권한이 필요하며 이를 위해 /home/$id/ 디렉토리를 701 권한으로 변경합니다.
 실행하시겠습니까? [y/N]:"
read check
if [ $check != "y" ] && [ $check != "Y" ];then
 exit
fi
echo -e "${hr}$home/$id 디렉토리 권한을 변경합니다."
chmod 701 $home/$id
echo -e "${hr}$home/$id/$www 디렉토리를 생성합니다."
mkdir $home/$id/$www
chown $id $home/$id/$www
chgrp $id $home/$id/$www
chmod 755 $home/$id/$www


### VirtualHost ###
echo -e "${hr}$vhost 파일에 VirtualHost 설정을 추가합니다.
Apache를 재시작합니다.
 도메인을 입력해주세요 [elkha.kr] 취소 [n]:"
read domain
if [ $domain = "n" ] || [ $domain = "N" ] || [ $domain = "" ];then
 exit
fi
echo -e "${hr}
### $id ###
<VirtualHost *>
 ServerAdmin $email
 DocumentRoot $home/$id/$www
 ServerName $domain
 ServerAlias *.$domain
 php_admin_value doc_root $home/$id
 php_admin_value user_dir $home/$id/$www
</VirtualHost>

 입력하신 정보가 맞습니까? [y/N]:"
read check
if [ $check != "y" ] && [ $check != "Y" ];then
 exit
fi

echo "

### $id ###
<VirtualHost *>
 ServerAdmin $email
 DocumentRoot $home/$id/$www
 ServerName $domain
 ServerAlias *.$domain
 php_admin_value doc_root $home/$id
 php_admin_value user_dir $home/$id/$www
</VirtualHost>" >> $vhost

$apachectl restart


echo -e "${hr}$vhost 파일을 수정하였습니다."
# chmod -x /bin/useradd.sh
# chmod 755 /bin/useradd.sh
# /bin/useradd.sh

hosting.jpg

번호 제목 날짜 조회 수
81 검색엔진 등록 file 2010.05.12 142341
80 VPS (가상 호스팅) 비교 file 2010.05.12 62201
79 마인크래프트 조합법 1 file 2011.04.01 38372
78 CentOS 6 - Apache 2.4.1 컴파일 / 보안 설정 [1] 2012.04.15 30240
77 리눅스 계정 생성/변경 [67] 2011.04.02 29128
76 Linux Memory 사용량 file 2012.05.16 24984
75 CentOS 6 - MySQL 5.5 설치 [1] file 2012.04.15 21722
74 Lighttpd 설치 file 2010.05.11 20679
73 sAPM file 2010.05.12 20261
72 php + ssh2 file 2010.06.05 20199
71 Linux 설치시 파티션 관리 file 2012.05.12 19206
70 Zend Optimizer + eAccelerator + Suhosin file 2010.05.11 18249
69 MySQL 설치 file 2010.05.11 17280
68 CentOS 6.2 다운로드 / 설치 [1] file 2012.04.15 17029
67 Apache 설치 file 2010.05.11 16658
66 ssh 로그인 제한 2011.04.05 16470
65 리눅스 자동 시작 file 2010.05.21 15895
64 ftp file 2010.07.23 15443
63 솔라리스 mount options 2013.10.06 15323
62 PHP 설치 file 2010.05.11 15057