[CentOS 7] CentOS 7 FTP 설치 및 설정하기

728x90
반응형

 

 

FTP 서버 구축 순서

1. vsftpd 패키지설치

2. 서버 설정 (conf 파일 및 허용리스트 작성)

3. 방화벽 설정 & selinux해제

4. 데몬재시작

5. 추가사항

6. 재시작 에러시 대처

 

 


 

1. vsftpd 패키지 설치

grep 명령어를 이용해서 vsftpd 가 설치 되어 있는지 확인 합니다. 

[root@localhost /]# ps -ax | grep vsftpd
 79682 pts/2    R+     0:00 grep --color=auto vsftpd

 

이후 yum 명령어를 이용해서 vsftpd 패키지를 설치 합니다. 

[root@localhost /]# yum -y install vsftpd

 


 

2. 서버설정

conf 파일을 이용해서, ftp 관련한 설정을 해줍니다. 해당 경로는 아래를 참고해주세요.

[root@localhost etc]# vi /etc/vsftpd/vsftpd.conf
[root@localhost etc]#

 

해당 conf 파일에서 저는 아래 3개의 설정을 변경했습니다. 

익명 허용 여부와, 허용 리스트를 관리해주는 부분입니다. 

anonymous_enable=YES

chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list

 

ESC 키를 누르고 :set nu 를 입력하면, 아래와 같이 줄 수가 표시됩니다. 

 

 

 

허용리스트 파일을 아래와 같이 conf 파일에 설정 해 주었기 때문에, 해당 경로에 허용할 아이디 리스트를 입력하여 줍니다. 

 

chroot_listchroot_list_file=/etc/vsftpd/chroot_list

 

[root@localhost etc]# vi /etc/vsftpd/chroot_list
[root@localhost etc]#

 


 

3. 방화벽 설정

기본적으로 FTP는 21번 포트를 사용합니다. 리눅스의 경우 웬만한 방화벽은 막혀 있다고 보시면 됩니다. 

그래서 firewall-cmd 명령어를 이용해서 방화벽을 해제해 줍니다. 

저는 그냥 21번 기본 포트를 사용하였으며, 원하시는 포트로 변경해도 됩니다. 

[root@localhost etc]# firewall-cmd --permanent --add-service=ftp
success
[root@localhost etc]# firewall-cmd --permanent --add-port=21/tcp
success
[root@localhost etc]# firewall-cmd --reload
success
[root@localhost etc]#

 

 

SELINUX 해제

 

SELinux 는 Linux의 보안을 강화해 주는 보안 강화 커널이고 zero-day 공격 및 buffer overflow 등 어플리케이션 취약점으로 인한 해킹을 방지해 주는 핵심 구성요소입니다. 

SELinux 는 저도 공부가 더필요한 영역이라, 자세한 설정은 여기서 다루지 않겠습니다. 

일단 SELINUX를 해제하는 방식으로 보안의 영역을 최소화 하겠습니다. 

 

[root@localhost etc]# vi /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=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

SELINUX=enforcing 을 disabled로 변경하여 준다.

 


 

4. 데몬 재시작

[root@localhost etc]# systemctl enable vsftpd

[root@localhost etc]# systemctl restart vsftpd

 

 


5. 추가 사항

간혹 root 계정을 이용해서 FTP 에 접속하는 경우 503 에러를 발생하는 경우가 있는데요. 이는 root 계정이 접속 거부 리스트에 등록되어 있는 경우 입니다. 

 

root 거부리스트 계정 제거

아래 각각 명령어를 이용해서 보여지는 리스트에서 root 계정을 제거해 줍니다. 

[root@localhost ~]# vi /etc/vsftpd/ftpusers


[root@localhost ~]# vi /etc/vsftpd/user_list

# Users that are not allowed to login via ftp
root -> 제거
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody

 

 


 

6. 재시작 에러시 대처

재시작할 경우 아래와 같은 오류가 발생하는 경우가 있습니다. 

이는 IPv4 / IPv6 와 관련된 에러내용이며, 둘다 YES 로 되어 있는 경우 발생하는 오류입니다.

vsftpd.conf 파일을 이용해서 listen=YES, listen_ipv6=YES 두 영역을 찾아서 하나를 NO로 변경해줍니다. 

보통 IPv6를 사용안하시기 때문에, 저의 경우 listen_ipv6를 NO 로 변경하였습니다. 

 

[root@localhost ~]# systemctl start vsftpd
Job for vsftpd.service failed because the control process exited with error code. See "systemctl status vsftpd.service" and "journalctl -xe" for details.

[root@localhost ~]# systemctl status vsftpd.service
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 화 2020-02-25 14:20:28 KST; 12s ago
  Process: 1475 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=2)

 2월 25 14:20:28 localhost.localdomain systemd[1]: Starting Vsftpd ftp daemon...
 2월 25 14:20:28 localhost.localdomain vsftpd[1475]: 500 OOPS: can only support ipv4 and ipv6 currently
 2월 25 14:20:28 localhost.localdomain systemd[1]: vsftpd.service: control process exited, code=exited status=2
 2월 25 14:20:28 localhost.localdomain systemd[1]: Failed to start Vsftpd ftp daemon.
 2월 25 14:20:28 localhost.localdomain systemd[1]: Unit vsftpd.service entered failed state.
 2월 25 14:20:28 localhost.localdomain systemd[1]: vsftpd.service failed.

 

    112 # When "listen" directive is enabled, vsftpd runs in standalone mode and
    113 # listens on IPv4 sockets. This directive cannot be used in conjunction
    114 # with the listen_ipv6 directive.
    115 listen=YES
    116 #
    117 # This directive enables listening on IPv6 sockets. By default, listening
    118 # on the IPv6 "any" address (::) will accept connections from both IPv6
    119 # and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
    120 # sockets. If you want that (perhaps because you want to listen on specific
    121 # addresses) then you must run two copies of vsftpd with two configuration
    122 # files.
    123 # Make sure, that one of the listen options is commented !!
    124 listen_ipv6=NO
728x90