백업용으로 진행하기 때문에 보안성보단 사용성에 촛점을 맞춰 진행하였다.
1. CentOS 6.6 minimal 설치 및 셋팅
CentOS 설치 후 진행
나는 hostname : localhost, 시간 : Seoul 로 진행하였다.
1) SELinux 해제
# vi /etc/sysconfig/selinux
7 SELINUX=disabled
*
라인 넘버 나타내기는 esc를 누른 뒤 :se nu 를 입력
입력 모드로 넘어갈 때엔 i 버튼
vi 편집기 저장 후 나가기는 esc를 누른 뒤 :wq 를 입력하면 된다.
2) iptables 해제
# iptables -X
# iptables -F
# chkconfig iptables off
3) 필요 패키지 설치 및 자동실행 설정
# yum install -y ntp vsftpd httpd mysql* php*
# chkconfig ntpd on
# chkconfig vsftpd on
# chkconfig httpd on
# chkconfig mysqld on
설정 적용을 위해 재시작
# reboot
2. 백업본 다운로드 및 업로드
1) 다운로드
백업본은 호스팅 업체에서 제공해준다.
2) 업로드
아래처럼 수정 후 재시작
# vi /etc/vsftpd/user_list
7 #root
# vi /etc/vsftpd/ftpusers
2 #root
# service vsftpd restart
이제 파일질라 등의 ftp client 프로그램을 이용하여 root 계정으로 업로드
3) 웹페이지 설정
백업받은 파일을 압축 풀어 웹 root 페이지로 이동
# tar xvfz u347840964.tar.gz
# rm -rf /var/www/html/
# mv u347840964/public_html/ /var/www/html
3. DB 설정
1) 사용할 DB 생성
# mysqladmin -u root password xxxx
# mysql -u root -p
mysql> CREATE DATABASE xe;
mysql> GRANT ALL PRIVILEGES ON xe.* TO root@localhost IDENTIFIED BY 'xxxx' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> quit
2) 업로드 한 DB 파일을 내 DB에 연결
# gzip -d u347840964_data.sql.gz
# mysql -u root -p xe < u347840964_data.sql
4. 허가권 및 xe 설정
1) 허가권 설정
# chmod 777 /var/www/html/
2) xe 설정 - db
# cd /var/www/html/files/config/
자신의 환경에 맞게 수정
# vi db.config.php
3 'master_db' =>
4 array (
5 'db_type' => 'mysqli',
6 'db_port' => '3306',
7 'db_hostname' => 'localhost',
8 'db_userid' => 'root',
9 'db_password' => 'xxxx',
10 'db_database' => 'xe',
11 'db_table_prefix' => 'xe_',
12 ),
13 'slave_db' =>
14 array (
15 0 =>
16 array (
17 'db_type' => 'mysqli',
18 'db_port' => '3306',
19 'db_hostname' => 'localhost',
20 'db_userid' => 'root',
21 'db_password' => 'xxxx',
22 'db_database' => 'xe',
23 'db_table_prefix' => 'xe_',
26 'default_url' => 'http://3.3.3.4',
3) xe 설정 - ftp
자신의 설정에 맞게 수정하여 기재
# vi ftp.config.php
1 <?php if(!defined("__XE__")) exit();
2 $ftp_info = new stdClass;
3 $ftp_info->ftp_user = 'root';
4 $ftp_info->ftp_port = '21';
5 $ftp_info->ftp_host = '3.3.3.4';
6 $ftp_info->ftp_pasv = 'Y';
7 $ftp_info->sftp = 'N';
8 $ftp_info->ftp_root_path = '/var/www/html/';
9 ?>
4) 짧은 주소 사용 - httpd
아래처럼 수정하면 짧은 주소를 사용할 수 있다.
(호스팅 업체에서 짧은 주소를 사용하고 있던 경우)
(참고 : http://www.xeschool.com/xe/xenote_module_urls)
# vi /etc/httpd/conf/httpd.conf
304 AllowOverride ALL
338 AllowOverride ALL
5) 설정들 적용을 위하여 서비스 재시작
# service mysqld restart
# service httpd restart
# service vsftpd restart
5. 웹 상에서의 재설정
1) 캐쉬파일 재 생성
리눅스 재부팅이 완료 되면 웹 브라우저를 통해 http://3.3.3.4/?module=admin 접속하여 로그인 한다.
화면 맨 밑 캐쉬파일 재생성 버튼을 누른다.
2) 설정 - 일반 - 고급
관리자 IP대역 설정
3) 설정 - FTP 설정
기본
설치된 XE의 FTP 경로 : / (목록 가져오기 클릭)
고급
Passive 모드 사용 : 아니오
* '요청한 기능을 실행할 수 있는 권한이 없습니다.' 의 경우
(출처 : https://www.xpressengine.com/tip/22751988)
파일 다운로드
FTP 접속하여 이 파일을 /var/www/html/classes/module/ 경로에 업로드하면 관리페이지에 접속이 가능
'XE' 카테고리의 다른 글
| XE 게시판에 구글 애드센스 광고하기 (0) | 2015.05.07 |
|---|---|
| 09. XE를 이용한 홈페이지 꾸미기 (5) - Home 화면에 위젯 설정하기! (0) | 2015.03.26 |
| 08. XE를 이용한 홈페이지 관리 - 회원가입 및 로그인 (0) | 2015.03.26 |
| 07. XE를 이용한 홈페이지 꾸미기 (4) - 모바일 홈 (0) | 2015.03.26 |
| 06. XE를 이용한 홈페이지 꾸미기 (3) - 게시판 (0) | 2015.03.26 |
- 2014.11.26
/backup/ 에 있는 grub.conf, inittab, login.defs 파일을 현재 위치로 복사한 뒤 실습을 시작한다.
1. gzip
gzip option source
: 압축
-d : 압축 해제
gzip 압축
# gzip ./grub.conf
# ll
합계 12
-rw------- 1 root root 476 2014-11-26 12:58 grub.conf.gz
-rw-r--r-- 1 root root 884 2014-11-26 12:58 inittab
-rw-r--r-- 1 root root 1816 2014-11-26 12:58 login.defs
=> 원본 파일이 없어진 것 확인 할 수 있다.
gzip 압축해제
# gzip -d ./grub.conf.gz
-- decompress
# ll
합계 12
-rw------- 1 root root 739 2014-11-26 12:58 grub.conf
-rw-r--r-- 1 root root 884 2014-11-26 12:58 inittab
-rw-r--r-- 1 root root 1816 2014-11-26 12:58 login.defs
=> 역시 원본 압축 파일 없어짐
여러 파일 압축
# gzip ./*
# ll
합계 12
-rw------- 1 root root 476 2014-11-26 12:58 grub.conf.gz
-rw-r--r-- 1 root root 884 2014-11-26 12:58 inittab.gz
-rw-r--r-- 1 root root 1816 2014-11-26 12:58 login.defs.gz
=> 동시에 묶이진 않고 각자 개별 파일로만 압축이 된다.
2. bzip2
# bzip2 option source
: 압축
-d : 압축 해제
bzip2 압축
# bzip2 ./grub.conf
# ll
합계 12
-rw------- 1 root root 542 2014-11-26 12:58 grub.conf.bz2
-rw-r--r-- 1 root root 884 2014-11-26 12:58 inittab
-rw-r--r-- 1 root root 1816 2014-11-26 12:58 login.defs
=> 원본 파일 없어짐
bzip2 압축 해제
# bzip2 -d ./grub.conf.bz2
# ll
합계 12
-rw------- 1 root root 739 2014-11-26 12:58 grub.conf
-rw-r--r-- 1 root root 884 2014-11-26 12:58 inittab
-rw-r--r-- 1 root root 1816 2014-11-26 12:58 login.defs
=> 원본 압축 파일 없어짐
* bzip2 역시 gzip과 마찬가지로 동시에 여러개 압축이 되지 않는다.
3. tar = tape Archive
tar option Archiving_file_name source
c - 보관하겠다.
x - 보관을 풀겠다.
v - verboss(보여주세요)
f - file
z - gzip 으로 압축 또는 해제
j - bzip2 으로 압축 또는 해제
-C path : path 에다 해당 작업 진행
cvf(생성), xvf(해제) 이 2가지 방식만 기억하면 된다
*Tip
tar 로 압축할 때엔 뒤에 .tar 를 붙여 tar 파일인 것을 남기는 습관이 좋다.
# tar cvf ./gc ./grub.conf
./grub.conf
# ll
합계 24
-rw-r--r-- 1 root root 10240 2014-11-26 13:33 gc
-rw------- 1 root root 739 2014-11-26 12:58 grub.conf
-rw-r--r-- 1 root root 884 2014-11-26 12:58 inittab
-rw-r--r-- 1 root root 1816 2014-11-26 12:58 login.defs
=> 이렇게 되면 gc라는 파일이 tar 파일인지 육안으로 확인하기 쉽지 않음
=> 카세트 테잎이나 CD처럼 안에 내용물이 얼마 들어가든 상관 없이 일정 공간이 생성된다.
# tar cvf ./gc.tar ./grub.conf
./grub.conf
# ll
합계 36
-rw-r--r-- 1 root root 10240 2014-11-26 13:33 gc
-rw-r--r-- 1 root root 10240 2014-11-26 13:34 gc.tar
-rw------- 1 root root 739 2014-11-26 12:58 grub.conf
-rw-r--r-- 1 root root 884 2014-11-26 12:58 inittab
-rw-r--r-- 1 root root 1816 2014-11-26 12:58 login.defs
=> tar 파일 확인 쉬움
[실습]
grub.conf 를 일단 지우고 tar 풀어보자
# rm ./grub.conf
# tar xvf ./gc.tar
./grub.conf
# ll
합계 36
-rw-r--r-- 1 root root 10240 2014-11-26 13:33 gc
-rw-r--r-- 1 root root 10240 2014-11-26 13:34 gc.tar
-rw------- 1 root root 739 2014-11-26 12:58 grub.conf
-rw-r--r-- 1 root root 884 2014-11-26 12:58 inittab
-rw-r--r-- 1 root root 1816 2014-11-26 12:58 login.defs
=> 압축 명령어들과 다르게 tar는 파일이 그대로 있는 것을 확인할 수 있다.
[문제]
현재 디렉터리에 있는 파일(grub.conf, inittab, login.defs)을 gil.tar 로 보관시켜보세요
# tar cvf gil.tar ./grub.conf ./inittab ./login.defs
tar 파일을 gzip 으로 압축
# gzip ./gil.tar
# ll
합계 4
-rw-r--r-- 1 root root 1953 2014-11-26 13:37 gil.tar.gz
이 압축된 파일을 /backup/ 에 압축 푸세요
# gzip -d ./gil.tar.gz
# tar xvf ./gil.tar
# mv ./grub.conf ./inittab ./login.defs /backup/
* Tip
tar 로 해제할 떄엔 현재 자신이 위치한 곳에 풀린다.
[실습 - 교재]
# tar cvf ./xinetd.tar /etc/xinetd.d/
tar: Removing leading `/' from member names
/etc/xinetd.d/
/etc/xinetd.d/rsync
# ll
합계 12
-rw-r--r-- 1 root root 10240 2014-11-26 13:53 xinetd.tar
# tar xvf ./xinetd.tar
etc/xinetd.d/
etc/xinetd.d/rsync
# ll
합계 16
drwxr-xr-x 3 root root 4096 2014-11-26 13:54 etc
-rw-r--r-- 1 root root 10240 2014-11-26 13:53 xinetd.tar
# ll ./etc/
합계 4
drwxr-xr-x 2 root root 4096 2014-10-30 01:57 xinetd.d
# ll ./etc/xinetd.d/
합계 4
-rw-r--r-- 1 root root 332 2014-03-28 19:54 rsync
=> tar는 내가 지정해준 디렉터리 까지, 경로 자체를 보관한다.
=> 또한 풀 때에는 내가 있는 경로 기준으로 풀린다.
[문제]
/bin 디렉터리의 모든 파일을 gzip 압축 및 tar 로 묶어서
/home 디렉터리 안에 binlist.tar.gz 라는 파일로 생성
# tar cvf /home/binlist.tar /bin/
tar: Removing leading `/' from member names
/bin
...
/bin/zcat
# ll
합계 8696
-rw-r--r-- 1 root root 8888320 2014-11-26 13:58 binlist.tar
drwxr-xr-x 3 root root 4096 2014-11-26 13:54 etc
-rw-r--r-- 1 root root 10240 2014-11-26 13:53 xinetd.tar
# gzip /home/binlist.tar
# ll /home
합계 4019
drwx------ 4 badnom badnom 1024 2014-11-25 15:01 badnom
-rw-r--r-- 1 root root 4100186 2014-11-26 13:58 binlist.tar.gz
drwx------. 2 root root 12288 2014-10-30 01:51 lost+found
* # gzip /bin/* 해서 /bin/ 것이 다 날라간 경우
백업 해놓은 gzip 명령 파일을 일반 계정으로 ftp 통해 업로드한다.
하지만 업로드 한 압축파일은 실행파일이 아니기 때문에 GUI 환경 통해 해당 파일을 실행파일로 속성 변경이 필요하다.
만약 GUI로 고칠 수 없는 상황이면 복구가 불가능하다. (가장 기초적인 명령어들이 bin 에 있기 때문)
# ./gzip -d /bin/*
=> /bin 에 .gz 로 개별적으로 묶여있던 파일들이 압축 해제된다. */
위의 문제를 bzip2 로 똑같이 진행
# tar cvf /home/binlist.tar /bin/
tar: Removing leading `/' from member names
/bin/
...
/bin/rnano
# bzip2 /home/binlist.tar
# ll /home/
합계 7611
drwx------ 4 badnom badnom 1024 2014-11-25 15:01 badnom
-rw-r--r-- 1 root root 3677201 2014-11-26 14:22 binlist.tar.bz2
-rw-r--r-- 1 root root 4100186 2014-11-26 13:58 binlist.tar.gz
drwx------. 2 root root 12288 2014-10-30 01:51 lost+found
[정리]
- gzip, bzip2 (압축)
1. 용량 작아짐
2. 원본 삭제
3. 단일 파일만 가능
4. 큰 파일의 압축 효율은 bzip2가 더 좋다.
- tar (보관)
1. 용량 커짐
2. 원본 유지
3. 다중파일 가능
4. tar + 압축
tar로 묶으면서 동시에 압축하기
# tar cvfz filename.tar.gz source
# tar cvfj filename.tar.bz2 source
압축 해제까지 한꺼번에 하기
# tar xvfz filename.tar.gz
# tar xvfj filename.tar.bz2
2가지 방법으로 /bin/ 디렉터리를 압축하세요
# tar cvfz ./binlist.tar.gz /bin/
# tar cvfj ./binlist.tar.bz2 /bin/
# ll
합계 7688
-rw-r--r-- 1 root root 3677201 2014-11-26 14:38 binlist.tar.bz2
-rw-r--r-- 1 root root 4103268 2014-11-26 14:37 binlist.tar.gz
drwxr-xr-x 3 root root 4096 2014-11-26 13:54 etc
-rwxr-xr-x 1 samadal samadal 67500 2014-11-26 14:11 gzip
-rw-r--r-- 1 root root 10240 2014-11-26 13:53 xinetd.tar
[문제]
현재 디렉터리에 있는 binlist.tar.xx 파일을 경로이동 하지 말고
/home/ 디렉터리에 풀어보세요
# tar xvfzC ./binlist.tar.gz /home/
# tar xvfj ./binlist.tar.bz2 -C /home/
아래 방식이 햇갈리지 않고 편리한 것 같다.
* 도움말 보기
# tar --help
# man tar
'Study > CentOS' 카테고리의 다른 글
| [17] rpm(2), yum (0) | 2015.03.28 |
|---|---|
| [16] rpm(1) (0) | 2015.03.28 |
| [14] SETUID, SETGID, Stickybit, UMASK (0) | 2015.03.28 |
| [13] 계정 복구, 계정 관련 Trouble Shooting, chown -R (0) | 2015.03.28 |
| [12] 소유권, 허가권 실습, ftp 관련 권한 (0) | 2015.03.28 |
- 2014.11.25
p74
원래 소유주에게 권한을 빌려와서 실행할 때만 소유권을 가짐
SETUID 4777 r w s r w x r w x
SETGID 2777 r w x r w s r w x
Sticky bit 1777 r w x r w x r w t
S,s / T,t : x 권한의 유무에 따라 없으면 S(대문자), 있으면 s(소문자) 이다.
1. Sticky bit
[실습]
# mkdir /sb/
# useradd badnom
samadal 계정으로 /sb/ 디렉터리에 testfile 생성 위해 757 권한 부여
# chmod 757 /sb/
[samadal@samadal ~]$ touch /sb/testfile
badnom 이 해당 파일 삭제
[badnom@samadal ~]$ rm /sb/testfile
rm: remove write-protected 일반 빈 파일 `/sb/testfile'? y
관리자가 해당 사태를 보고 Sticky bit 를 진행.
# chmod 1777 /sb/
# ll -d /sb/
drwxrwxrwt 2 root root 4096 2014-11-25 13:06 /sb/
samadal 이 한번 더 올린다.
[samadal@samadal ~]$ touch /sb/testfile
badnom 이 한번 더 삭제를 시도하지만 실패
[badnom@samadal ~]$ rm /sb/testfile
rm: remove write-protected 일반 빈 파일 `/sb/testfile'? y
rm: cannot remove `/sb/testfile': 명령을 허용하지 않음
즉, Sticky bit 는 소유자만 삭제하게 할 수 있다. 공유폴더에 많이 쓰는 권한.
samadal로는 지워진다.
[samadal@samadal ~]$ rm /sb/testfile
[samadal@samadal ~]$ ll /sb/
합계 0
* /tmp/ 디렉터리가 대표적인 Sticky bit 를 사용하는 예
2. SetUID
[실습]
find 명령어 활용하여 오늘 쓴 명령어 중 SetUID 적용된 명령어 찾기
ex)
# find / -name chmod
passwd에 SetUID가 설정된 것을 확인
# find / -name passwd -exec ls -l {} \;
-rwsr-xr-x. 1 root root 25980 2012-02-22 20:44 /usr/bin/passwd
-rw-r--r--. 1 root root 1666 2014-11-25 12:57 /etc/passwd
-rw-r--r--. 1 root root 146 2012-02-22 20:44 /etc/pam.d/passwd
이 passwd 명령어에 SetUID 빼고 samadal로 passwd 변경을 다시 시도 해보자.
/usr/bin/passwd 명령어실행 p/w변경
4755
rwsr-xr-x O O
755
rwxr-xr-x O X
4750
rwsr-x--- X X
*
other의 실행 권한이 0이면 실행 자체도 안된다. 일반적으로 서버에서는 보안상 4750 권한을 준다.
*
/usr/bin/passwd 명령어 소스파일 자체 안에 root만 변경 가능하도록 되어있다.
(x 권한은 컴파일, 링커를 거쳐야지만 생성됨. 즉 일반 파일의 Max 권한은 666이라 할 수 있다.)
3. SetGID
[실습]
# cd ~samadal
# mkdir ./testdir/
# touch ./testdir/test
# chown .samadal ./testdir/
# ll
합계 4
-rwsr--r-- 1 root root 0 2014-11-25 12:53 test
drwxr-xr-x 2 root samadal 4096 2014-11-25 13:59 testdir
그룹 소유권이 samadal인 디렉터리에 test2 생성
# touch ./testdir/test1
# ll ./testdir
합계 0
-rw-r--r-- 1 root root 0 2014-11-25 13:59 test
-rw-r--r-- 1 root root 0 2014-11-25 13:59 test1
=> dir의 GID가 samadal이라 해도 파일을 생성하면 소유권은 root:root 이다.
SetGID 설정
# chmod 2755 ./testdir/
# ll
합계 4
-rwsr--r-- 1 root root 0 2014-11-25 12:53 test
drwxr-sr-x 2 root samadal 4096 2014-11-25 13:59 testdir
SetGID 설정 된 디렉터리에 test2 생성
# touch ./testdir/test2
# ll ./testdir/
합계 0
-rw-r--r-- 1 root root 0 2014-11-25 13:59 test
-rw-r--r-- 1 root root 0 2014-11-25 13:59 test1
-rw-r--r-- 1 root samadal 0 2014-11-25 14:00 test2
=> test2 그룹 소유자가 SetGID 디렉터리의 소유주를 따라감
SetGID : 해당 권한이 있는 디렉터리 안에 파일이나 디렉터리 생성되면 해당 소유주를 따라 소유주가 자동 변경.
[실습]
./testdir/ 을 4755 로 권한 변경
# chmod 4755 ./testdir/
# ll
합계 4
-rwsr--r-- 1 root root 0 2014-11-25 12:53 test
drwsr-sr-x 2 root samadal 4096 2014-11-25 14:00 testdir
=> GID의 s가 chmod 4755 명령어로는 바뀌지 않는다.
# chmod g-s ./testdir/
# ll
합계 4
-rwsr--r-- 1 root root 0 2014-11-25 12:53 test
drwsr-xr-x 2 root root 4096 2014-11-25 14:00 testdir
=> 변경 완료
[문제]
옵션을 찾아서 아래의 설명에 필요한 대로 각 한번의 명령어로 디렉터리를 생성한다.
1) /tmp/test/test1/test2/ 디렉터리 생성
2) /tmp/test 디렉터리는 Sticky bit, 모든 사용자가 모든 권한 가짐
3) /tmp/test/test1 디렉터리 소유자는 모든 권한을, 그룹은 읽기 및 실행권한, 다른 유저는 실행권한을 가진다.
4) /tmp/test/test1/test2/ 디렉터리는 소유자는 모든 권한을, 그룹은 읽기 권한을, 다른 유저는 아무런 권한 없음
# mkdir -p /tmp/test/test1/test2/
# chmod 1777 /tmp/test/
# chmod 751 /tmp/test/test1/
# chmod g-x,o-rx /tmp/test/test1/test2/
* SetUID 위험성
특정 소스파일을 실행 시 자동으로 root 권한 획득하는 프로그램 심어두고 해킹에 악용될 수 있다.
그렇기 때문에 서버관리자는 SetUID 적용된 리스트를 잘 관리해야 한다.
SetUID 적용된 파일 오류 제외하고 출력하라는 명령어
# find / -user root -perm +4000 2> /dev/null
4. UMASK
파일 및 디렉터리가 만들어질 때 기본적으로 설정될 사용권한을 결정
UMASK
Directory 관리자 d1 755 777 - 755 = 022
Max : 777 사용자 d2 775 777 - 775 = 002
File 관리자 f1 644 666 - 644 = 022
Max : 666 사용자 f2 664 666 - 664 = 002
1) UMASK 사용 예
# vi /etc/login.defs
57 # the permission mask will be initialized to 022.
58 UMASK 077
59
2) umask 확인
# umask
0022
[samadal@samadal ~]$ umask
0002
[umask 실습]
# umask 000
# umask
0000
# mkdir ./t1/
# touch ./t2
# ll
합계 7
drwxrwxrwx 2 root root 4096 2014-11-25 14:45 t1
-rw-rw-rw- 1 root root 0 2014-11-25 14:45 t2
=> t1과 t2의 권한이 최대로 되어있다.
# umask 123
# mkdir ./t3/
# ll
합계 11
drwxrwxrwx 2 root root 4096 2014-11-25 14:45 t1
-rw-rw-rw- 1 root root 0 2014-11-25 14:45 t2
drw-r-xr-- 2 root root 4096 2014-11-25 14:46 t3
=> 하지만 이렇게 변경된 umask 는 현재 열려있는 터미널에서만 먹힌다.(1회성)
이곳의 설정 값을 바꾸면 영구적인 변경이 가능하다.
# vi /etc/profile
58 # By default, we want umask to get set. This sets it for login shell
59 # Current threshold for system reserved uid/gids is 200
60 # You could check uidgid reservation validity in
61 # /usr/share/doc/setup-*/uidgid file
62 if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
63 umask 002
64 else
65 umask 022
[문제]
473 이라는 허가권을 갖는 d3와 f3를 만들기 위한 umask 값은?
=> 304
256 이라는 허가권을 갖는 d4와 f4를 만들기 위한 umask 값은?
=> 521
'Study > CentOS' 카테고리의 다른 글
| [16] rpm(1) (0) | 2015.03.28 |
|---|---|
| [15] gzip, bzip2, tar, man (0) | 2015.03.28 |
| [13] 계정 복구, 계정 관련 Trouble Shooting, chown -R (0) | 2015.03.28 |
| [12] 소유권, 허가권 실습, ftp 관련 권한 (0) | 2015.03.28 |
| [11] 허가권, 소유권, chmod, chown, chgrp (0) | 2015.03.28 |
ModuleHandler.class.php

