linux class(new) 1 페이지

본문 바로가기
사이트 내 전체검색


회원로그인

linux class(new)

ftp 서비스 - server

페이지 정보

작성자 admin 작성일16-02-24 18:00 조회908회 댓글0건

본문

ftp 서버

- 리눅스에서 주로 사용되는 ftp 서버는 몇가지가 있는데 다음과 같은 특징을 갖고 있다.
proftpd - 매직쿠키를 지원하며 많은 설정 옵션이 있어서 세밀하고 다양한 설정을 할 수 있지만 다른 ftp 서버에
비해서 설정문법이 복잡하고 보안성은 vsftpd 에 비해서 떨어진다.
pureftpd - 사용자가 많지 않고 간단하게 서버를 구성해서 운영하는 경우에 적합
vsftpd - 사용자가 많고 보안성이 중요한 경우에 적합(요즘의 리눅스 배포판에는 주로 vsftpd 가 포함되어 있다)

여기서는 vsftpd 서버를 구성하는것으로 한다.
실습을 위해서 vsftpd 서버와 ftp 클라이언트의 설치유무를 확인해서 설치안되어 있으면 설치해야 한다.
서버와 클라이언트를 쉽게 구분하기위해서 centos(server1)에서 shell prompt 를 변경한다.

centos[/root]# PS1="svr1[\u \$PWD]# "
svr1[root /root]#

그리고 client 의 hosts 파일에는 centos 서버의 별명으로 svr1 을 추가.
예를 들면 아래처럼 맨 뒤에 별명을 하나 추가한다.

centos2[/root]# grep -w centos /etc/hosts
172.20.1.100 centos server1 svr1
centos2[/root]#


vsftpd 서버 주요옵션(man vsftpd.conf 참조)
- 옵션의 기본형태는 option=value ; '=' 사이에 빈칸이 들어가면 안된다. 에러남.
- 옵션의 종류는 세가지가 있다.
첫번째 - boolean options ; 선택될수 있는 설정값이 YES, NO
두번째 - numeric options ; 선택될수 있는 설정값이 숫자
세번째 - string options ; 선택될수 있는 설정값이 문자열
* 각 옵션마다 디폴트 설정값이 있는게 디폴트 설정값은 설정파일에서 그 옵션이 없거나
주석처리되어있을때 해당 설정 옵션은 디폴트 설정 값으로 처리된다.

사용자 권한
1. anonymous(익명) 관련옵션
anonymous_enable=YES : 익명접속허용 여부
anon_upload_enable=NO : 익명접속 파일업로드 허용여부
anon_mkdir_write_enable=NO :익명접속시 디렉토리 생성허용 여부
anon_root=/var/ftp/pub : 익명 계정 홈디렉토리

2. local account 관련옵션
local_enable=YES : 로컬 계정 접속 허용 여부
local_umask=022 : 파일생성시 디폴트 권한 (umask값이 022 인경우 기본파일퍼미션:644, 기본디렉토리퍼미션:755)
chroot_list_enable=YES : chroot_list_file 설정 허용
chroot_list_file=/etc/vsftp/chroot_list : chroot 적용 받는 사용자
chroot_local_user=YES : 모든 사용자에게 chroot 기능 적용
userlist_deny=YES : userlist_file 옵션 허용여부
userlist_file=/etc/vsftpd/user_list : userlist_deny 가 YES 일때 이파일에 적혀
있는 사용자는 ftp 서버 접속불가

3. 메시지 출력 옵션
d) 출력 메세지 설정
ftpd_banner=Welcome to blah FTP service. ; 로그인 하기전 출력된다.
banner_file=/etc/vsftpd/welcome.msg ; 로그인하기전 출력, 두줄이상의 메시지라면 ftpd_banner 로
설정하기에 좋지 않으며 banner_file 옵션을 사용하는게 좋다.
dirmessage_enable=YES ; ftp 사용자가 특정디렉토리에 들어갔을때 메세지 출력
message_file=.messages ; dirmessage_enable 옵션과 관련되어 있다. 디폴트는 .message

4. logging 설정 옵션
xferlog_file=/var/log/xferlog : 로그 저장 파일
xferlog_enable=YES : 파일전송 기록 허용여부

5. 기타 설정
1) timeout 시간 설정
idle_session_timeout=60(초단위) : 접속후 아무것도 하지 않을때의 접속종료시간
data_connection_timeout=120 : 파일전송시 아무런 동작을 하지 않을때 접속 종료시
2) 동시접속자수 제한
max_clients=30 : 최대 동시접속자수는 30명으로 제한
max_per_ip=2 : 한 ip 당 동시접속을 계정과 상관없이 2개로 제한

실습하기전에 다음 세가지를 확인한다.
- vsftpd 서비스 실행 여부
- 방화벽 설정여부
- selinux 사용여부
- 편의상 방화벽은 해제하고 selinux 는 사용하지 않는것으로 한다.

svr1[root /root]# sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 24
Policy from config file: targeted

--- 사용중이다. selinux 를 따로 학습하기전까지 편의상 설정해제 한다.
selinux 설정을 해제 하려면 아래와 같이 설정하면 된다.

svr1[root /root]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

- config 파일에서 SELINUX=disabled 로 설정한다음 reboot 해야 한다.
- 설정해제 후 리부팅해서 selinux 설정확인

svr1[root /root]# sestatus
SELinux status: disabled

그 다음 방화벽 설정을 해제하고 vsftpd 가 실행중이지 않으면 실행한다.

svr1[root /root]# iptables -F
svr1[root /root]# pgrep -fl vsftpd
svr1[root /root]# service vsftpd start
vsftpd에 대한 vsftpd을 시작 중: [ OK ]
svr1[root /root]# pgrep -fl vsftpd
2376 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
svr1[root /root]#

- vsftpd 서버 실습준비 완료됨.

1. 익명계정 권한 설정 및 테스트

centos2[/root]# ftp svr1
Connected to svr1 (172.20.1.100).
220 (vsFTPd 2.2.2)
Name (svr1:root): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/"
ftp> ls
227 Entering Passive Mode (172,20,1,100,32,228).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 4096 Jul 24 2015 pub
226 Directory send OK.
ftp> cd /etc
550 Failed to change directory.
ftp>

- 익명계정은 로그인할때 암호가 없으며 보안상 익명계정 홈디렉토리를 벗어날수 없게 설정되어있다.
파일 업로드 설정은 디폴트로 막혀있다. 파일 다운로드는 가능하다.

2. local account 권한 설정 및 테스트
- 기존에 있는 일반계정으로 해도 되지만 여기서는 일반계정으로 ftpuser1 을 생성해서 테스트

svr1[root /root]# passwd ftpuser1
ftpuser1 사용자의 비밀 번호 변경 중
새 암호:
f잘못된 암호: 너무 짧습니다
잘못된 암호: 너무 간단함
passwd: 모든 인증 토큰이 성공적으로 업데이트 되었습니다.

- 이제 클라이언트에서 ftpuser1 계정으로 접속해서 테스트
centos2[/root]# ftp svr1
Connected to svr1 (172.20.1.100).
220 (vsFTPd 2.2.2)
Name (svr1:root): ftpuser1
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/home/ftpuser1"
ftp> cd /etc
250 Directory successfully changed.
ftp> pwd
257 "/etc"
ftp>
- 일반계정은 익명계정과 달리 자신의 홈디렉토리를 벗어나서 다른디렉토리로 이동할 수 있다.
- 보안상 일반계정이 홈디렉토리를 제외한 다른디렉토리에 있는 파일을 다운로드 받지 못하게 하려면
일반계정에 대한 chroot 설정을 해야한다.
*. chroot (chnage root directory) - 실제로는 루트(/) 디렉토리가 아니지만 특정 디렉토리이외에
다른 디렉토리에 대한 access 를 차단하기 위해서 특정디렉토리를 루트(/) 디렉토리로 취급하는 설정.
일반계정한테 chroot 기능을 적용하려면 아래에 세가지 설정 옵션을 참고.
chroot_list_file=/etc/vsftp/chroot_list : chroot 적용 받는 사용자
chroot_local_user=YES : 모든 사용자에게 chroot 기능 적용
userlist_deny=YES : userlist_file 옵션 허용여부

- chroot 를 설정한 경우

centos2[/root]# ftp centos
Connected to centos (172.20.1.100).
220 (vsFTPd 2.2.2)
Name (centos:root): ftpuser1
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/"
ftp> ls -a
227 Entering Passive Mode (172,20,1,100,245,16).
150 Here comes the directory listing.
drwx------ 4 545 545 4096 Feb 24 07:50 .
drwx------ 4 545 545 4096 Feb 24 07:50 ..
-rw-r--r-- 1 545 545 18 Jul 18 2013 .bash_logout
-rw-r--r-- 1 545 545 176 Jul 18 2013 .bash_profile
-rw-r--r-- 1 545 545 124 Jul 18 2013 .bashrc
-rw-r--r-- 1 545 545 500 May 07 2013 .emacs
drwxr-xr-x 2 545 545 4096 Nov 12 2010 .gnome2
drwxr-xr-x 4 545 545 4096 Apr 08 2014 .mozilla
226 Directory send OK.
ftp> cd /etc
550 Failed to change directory.
ftp> cd /home
550 Failed to change directory.
ftp>

- 자신의 홈디렉토리 이외에 다른 디렉토리로 이동할 수 없다.

- vsftpd 로그 파일
설정옵션
xferlog_file=/var/log/xferlog : 로그 저장 파일
xferlog_enable=YES : 파일전송 기록 허용여부

svr1[root /var/log]# cat /var/log/xferlog
Tue Feb 23 17:55:48 2016 1 172.20.1.200 0 /etc/issue* a _ o r fuser1 ftp 0 * i
Tue Feb 23 17:55:53 2016 1 172.20.1.200 47 /etc/issue a _ o r fuser1 ftp 0 * c
Tue Feb 23 17:55:54 2016 1 172.20.1.200 46 /etc/issue.net a _ o r fuser1 ftp 0 * c
Tue Feb 23 18:00:07 2016 1 172.20.1.200 47 /etc/issue a _ o r fuser1 ftp 0 * c
Tue Feb 23 18:00:07 2016 1 172.20.1.200 46 /etc/issue.net a _ o r fuser1 ftp 0 * c
Tue Feb 23 18:00:20 2016 1 172.20.1.200 641020 /etc/services a _ o r fuser1 ftp 0 * c
Tue Feb 23 18:00:54 2016 1 172.20.1.200 641020 /etc/services a _ o r fuser1 ftp 0 * c
Tue Feb 23 18:00:59 2016 1 172.20.1.200 47 /etc/issue a _ o r fuser1 ftp 0 * c
Tue Feb 23 18:01:59 2016 1 172.20.1.200 122872 /bin/cp a _ o r fuser1 ftp 0 * c
Tue Feb 23 18:02:01 2016 1 172.20.1.200 49384 /bin/mkdir a _ o r fuser1 ftp 0 * c
Tue Feb 23 18:02:17 2016 1 172.20.1.200 122872 /bin/cp a _ o r fuser1 ftp 0 * c
Wed Feb 24 17:19:32 2016 24 172.20.1.200 524288000 /test/testfile b _ o r ftpuser1 ftp 0 * c
svr1[root /var/log]#

- 로그파일저장형태
파일전송일시 파일전송시간(초단위) client주소 파일용량 파일명 전송모드 업로드및 다운로드
(man xferlog 참조)
ex)
Wed Feb 24 17:19:32 2016 24 172.20.1.200 524288000 /test/testfile b _ o r ftpuser1 ftp 0 * c
전송모드: a --> ascii mode , b --> binary mode
전송모드:업로드및 다운로드: o --> 다운로드 , i --> upload

*. 출력 메시지 설정
ftp 서비스 접속후 바로 특정 메시지가 출력되도록 하려면
한줄정도의 간단한 메시지 출력은 ftpd_banner 옵션을 사용하고
메시지가 두줄이상으로 길어지면 banner_file 옵션을 사용하면 된다.
ex)
vsftpd.conf 에
banner_file=/etc/vsftpd/welcome.message ; 한줄 추가후 저장 및 vsftpd 재시작

centos2[/root]# ftp svr1
Connected to svr1 (172.20.1.100).
220-
220-********************************************************
220- welcome my ftp server ^^
220- 아이디가 없으면 anonymous 계정으로 로그인하면 됩니다.
220- 접속에 문제가 있으면 kildong@google.com 으로 메일주세요.
220-********************************************************
220-
220
Name (svr1:root):

- 이것 외에도 로그인후 메시지가 자동으로 출력되게 할수 있으며 특정 디렉토리로
이동했을때만 그 디렉토리에 관련된 메시지가 자동으로 출력되게 할수 있다.
(옵션은 dirmessage_enable 과 message_file 옵션)
ex)

centos2[/root]# ftp svr1
Connected to svr1 (172.20.1.100).
220-
220-********************************************************
220- welcome my ftp server ^^
220- 아이디가 없으면 anonymous 계정으로 로그인하면 됩니다.
220- 접속에 문제가 있으면 kildong@google.com 으로 메일주세요.
220-********************************************************
220-
220
Name (svr1:root): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd pub
250 Directory successfully changed.
ftp> cd ..
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (172,20,1,100,226,97).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 4096 Feb 24 08:40 apache
drwxr-xr-x 2 0 0 4096 Jul 24 2015 pub
drwxr-xr-x 2 0 0 4096 Feb 24 08:38 putty
drwxr-xr-x 2 0 0 4096 Feb 24 08:38 upload
226 Directory send OK.
ftp> cd apache
250-
250-**************************************************************
250- 파일은 소스코드로 압축되어 있으며 다운로드 후
250- tar -xf 아파치파일명으로 압축을 풀면 됩니다.
250- 설치방법은 아파치디렉토리의 INSTALL 파일을 참조하세요.
250-**************************************************************
250-
250 Directory successfully changed.
ftp> cd ..
250 Directory successfully changed.
ftp> pwd
257 "/"
ftp> cd apache ; dirmessage_enable 로 설정된 디렉토리 관련 출력 메시지는
처음에 들어갔을때 한번만 출력된다. 다시 들어가면 메시지가 출력 안됨.
250 Directory successfully changed.
ftp>


vsftpd 프로세스 권한

svr1[root /]# ps -ef | grep vsftpd | grep -v grep
root 3099 1 0 17:34 ? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

- vsftpd 서비스를 실행하면 처음에는 root 권한으로 하나가 실행된다.
- 그다음 클라이언트에서 어떤 사용자가 ftp 서버로 접속을 하면

centos2[/root]# ftp centos
Connected to centos (172.20.1.100).
220-
220-********************************************************
220- welcome my ftp server ^^
220- 아이디가 없으면 anonymous 계정으로 로그인하면 됩니다.
220- 접속에 문제가 있으면 kildong@google.com 으로 메일주세요.
220-********************************************************
220-
220
Name (centos:root):

svr1 에서는

svr1[root /]# ps -ef | grep vsftpd | grep -v grep
root 3099 1 0 17:34 ? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
root 3264 3099 0 17:45 ? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
nobody 3265 3264 0 17:45 ? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
svr1[root /]#

- ftp 서버로 어떤 클라이언트가 접속을 하게 되면 로그인하기전에는 복제된 자식 프로세스가
두개가 하나는 root 권한으로 다른 하나는 다시 그 자식 프로세스로 nobody 권한으로 실행이 되며
로그인하기전 현재 접속자는 출력결과중에서 마지막라인의 nobody 권한의 프로세스에 연결되어 있다.
- 그리고 접속이 되어 있는 상태에서 특정계정으로 로그인하게 되면

Name (centos:root): ftpuser1
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

- 로그인된 상태에서 서버측에서 ftp 서버 프로세스 정보를 다시 출력하면

svr1[root /]# ps -ef | grep vsftpd | grep -v grep
root 3099 1 0 17:34 ? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
nobody 3264 3099 0 17:45 ? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
ftpuser1 3270 3264 0 17:45 ? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

- 프로세스 소유자가 현재 로그인한 계정으로 생성되고 거기에 접속되어 있음을 알수 있다.
- 클라이언트에서 접속을 끊고 나가면 복제된 자식 vsftpd 프로세스들은 다 종료된다.
- 익명 계정으로 로그인하는 경우에는

centos2[/root]# ftp svr1
Connected to svr1 (172.20.1.100).
220-
220-********************************************************
220- welcome my ftp server ^^
220- 아이디가 없으면 anonymous 계정으로 로그인하면 됩니다.
220- 접속에 문제가 있으면 kildong@google.com 으로 메일주세요.
220-********************************************************
220-
220
Name (svr1:root): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

- 익명계정으로 접속후 서버측에서 vsftpd 서비스 프로세스 정보를 출력해보면
익명계정은 ftp 권한의 vsftpd 에 연결되어 있음을 알수 있다.
(*. 프로세스 권한은 프로세스의 소유주 권한과 같다 - 디렉토리 엑세스나 파일 전송할때
권한문제로 제대로 되지 않으면 엑세스 하려는 디렉토리 및 파일의 권한과 프로세스 소유주 정보를
확인을 해야 한다)


svr1[root /]# ps -ef | grep vsftpd | grep -v grep
root 3099 1 0 17:34 ? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
nobody 3277 3099 0 17:46 ? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
ftp 3287 3277 0 17:46 ? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
svr1[root /]#

댓글목록

등록된 댓글이 없습니다.


접속자집계

오늘
29
어제
75
최대
611
전체
448,079
개인정보취급방침 서비스이용약관 twoseven.kr All rights reserved.
상단으로