CentOS 6.5 에 vsftpd 설치하고 FileZilla 로 접속하기
테스트 환경
Windows 7, VMware 10, CentOS 6.5, vsftpd 2.2, FileZilla 3.9.0.2
1. vsftpd 설치
yum info vsftpd
yum install vsftpd 혹은 yum -y install vsftpd
yum 설치 명령에 -y 옵션을 제공하면 설치 중간에 나오는 프롬프트에 자동으로 y (YES) 가 입력되므로 설치과정에서 중간에 멈춤이 없이 한번에 설치가 완료된다.
2. FTP 모드 설정
vim 에디터로 vsftpd.conf 설정파일을 열고 사용 모드에 따라서 아래와 같이 설정한다
vim /etc/vsftpd/vsftpd.conf
FTP 서버를 Active 모드로 사용하는 경우
pasv_enable=NO
FTP 서버를 Passive 모드로 사용하는 경우 (FTP 클라이언트 중 FileZila는 디폴트로 Passive 모드를 사용함)
listen=YES
listen_port=21
port_enable=YES
connect_from_port_20=YES
ftp_data_port=50050
pasv_enable=YES
pasv_min_port=50000
pasv_max_port=50100
참고 : 이용자의 FTP 루트 디렉토리를 지정하려면 vsftpd.conf 하단에 local_root=/usr/local/server/tomcat/webapps 와 같은 행을 추가하여 기본 디렉토리를 지정해주면 된다.
이렇게 하면 이용자가 FTP 클라이언트로 접속해오면 지정된 디렉토리에 바로 접속되고 이곳에 파일이 업로드된다
지정된 디렉토리에 파일이 업로드 되도록 하려면 쓰기 모드가 활성화 되어야 하므로 chmod 로 쓰기 가능하도록 설정해 주어야 한다
3. iptables 에 FTP 관련 포트 설정 (참고 http://x2soft.co.kr/programming/tipntech.php?CMD=print&IDX=690&source=overture)
[root@localhost kdea]# cat /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 20 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 21 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 50000:50100 -j ACCEPT
-A INPUT -p tcp -m tcp --sport 50000:50100 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
iptables 재시동 및 설정포트 상태확인
service iptables restart
iptables -nL
4. 익명 접속 제한
vim /etc/vsftpd/vsftpd.conf
anonymous_enable=NO
5. 상위 디렉토리 접근제한
vi /etc/vsftpd/vsftpd.conf
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
위와 같이 설정한 후에 /etc/vsftpd/chroot_list 파일에 계정 이름을 입력해주면 해당 계정 이용자는 상위 디렉토리 이동이 제한된다
디렉토리 접근 권한 설정 (SELINUX 수정)
vi /etc/selinux/config
SELINUX=disabled 로 수정
6. vsftpd 재시작 및 프로세스 실행여부 확인
service vsftpd restart
ps -ef | grep vsftpd, 혹은 아래처럼
netstat -ntlp
7. 시스템 부팅시 자동으로 vsftpd를 실행되도록 설정
chkconfig vsftpd on 혹은 아래처럼
chkconfig --level 2345 vsftpd on
자동 실행 설정확인
chkconfig --list 혹은 아래처럼
chkconfig --list | grep vsftpd
7. FTP 사용자 추가/삭제
useradd -g ftp user01
passwd user01
userdel user01
8. Windows 운영체제에 내장된 MS FTP 클라이언트를 이용한 FTP 서버 접속 테스트
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\duniv6-000>ftp 192.168.40.10
192.168.40.10에 연결되었습니다.
220 (vsFTPd 2.2.2)
사용자(192.168.40.10:(none)): user01
331 Please specify the password.
암호:
230 Login successful.
ftp>
9. FileZilla (FTP 클라이언트) 설치 및 서버에 접속
- FileZilla 다운로드 https://filezilla-project.org/
- CentOS 터미널에서 서버의 IP 주소 확인 ( VMware 를 재시동할 때마다 동적 IP가 변경되어 적용될 수 있으므로 아래처럼 수시로 확인할 필요가 있다)
ifconfig
inet addr : 192.168.40.10
FileZilla 실행/ 다음과 같이 입력하고[빠른연결] 버튼을 눌러 서버에 접속을 시도한다
호스트명: 192.168.40.10
사용자명: user01
비밀번호: 111111
포트 : 21
10. FileZilla 를 이용하여 접속한 결과 화면
"500 OOPS: cannot change directory:/home/" 에러 발생 예방을 위해 아래 내용 설정
setsebool -P ftp_home_dir 1
root 접속 허용 설정(root 라는 아이디와 해당 암호를 이용한 접속허용)
아래의 두 파일을 열고 root 계정명 왼쪽에 '#' 을 추가하여 주석으로 설정하면 root 계정으로 접속이 가능핟
vi /etc/vsftpd/ftpusers
vi /etc/vsftpd/user_list
chkconfig 사용법 (부팅시 자동으로 실행할 서비스에 대한 제어)
chkconfig --list
chkconfig --add vsftpd
To set the service to start during boot (Will add to runlevels 2,3,4 and 5).
chkconfig vsftpd on
chkconfig --level 3 vsftpd on
chkconfig vsftpd off
chkconfig --level 3 vsftpd off
chkconfig --del vsftpd
Linux runlevels (Runlevel – System State)
0 – Halt the system
1 – Single-user mode
2 – Multi-user mode (without NFS)
3 – Multi-user mode (cli)
4 – unused/reserved
5 – Multi-user mode, graphical login
6 – Reboot the system
터미널 (명령 프롬프트)에서 시스템의 Runlevel을 지정하여 해당 상태로 전환할 수 있다
init runlevel
Examples
reboot the system.
init 6
Start a gui when booted into terminal (switching from runlevel 3 to runlevel 5).
init 5
Shutdown the system.
init 0