OS/Linux

[ OralceLinux8 ] vsftpd 구성

RI_Twins 2023. 2. 11. 00:06

환경

- Oracle Linux 8

설치방법

  1. vsftpd 설치 가능 버전 확인 및 설치

# vsftpd 설치 가능 버전확인

[opc@ftp-test ~]$ sudo yum list vsftpd

Ksplice for Oracle Linux 8 (x86_64)   4.6 MB/s | 418 kB 00:00

MySQL 8.0 for Oracle Linux 8 (x86_64)  19 MB/s | 1.8 MB 00:00

MySQL 8.0 Tools Community for Oracle Linux 8 (x86_64) 2.1 MB/s | 151 kB 00:00

MySQL 8.0 Connectors Community for Oracle Linux 8 (x86_64) 90 kB/s |  17 kB 00:00

Oracle Software for OCI users on Oracle Linux 8 (x86_64)   66 MB/s |  13 MB 00:00

Oracle Linux 8 BaseOS Latest (x86_64) 124 MB/s |  36 MB 00:00

Oracle Linux 8 Application Stream (x86_64) 88 MB/s |  27 MB 00:00

Oracle Linux 8 Addons (x86_64)2.7 MB/s | 211 kB 00:00

Latest Unbreakable Enterprise Kernel Release 6 for Oracle Linux 8 (x86_64) 99 MB/s |  25 MB 00:00

Available Packages

vsftpd.src 3.0.3-33.el8  ol8_appstream

vsftpd.x86_64  3.0.3-33.el8  ol8_appstream

  

# vsftpd 설치

[opc@ftp-test ~]$ sudo yum install vsftpd -y

Last metadata expiration check: 0:02:54 ago on Fri 01 Oct 2021 07:50:13 AM GMT.

Dependencies resolved.

=====================================================================================================================================================

 Package ArchitectureVersionRepository  Size

=====================================================================================================================================================

Installing:

 vsftpd  x86_64  3.0.3-33.el8   ol8_appstream  180 k

  

Transaction Summary

=====================================================================================================================================================

Install  1 Package

  

Total download size: 180 k

Installed size: 343 k

Downloading Packages:

vsftpd-3.0.3-33.el8.x86_64.rpm   1.7 MB/s | 180 kB 00:00

-----------------------------------------------------------------------------------------------------------------------------------------------------

Total1.6 MB/s | 180 kB 00:00

Running transaction check

Transaction check succeeded.

Running transaction test

Transaction test succeeded.

Running transaction

  Preparing: 1/1

  Installing   : vsftpd-3.0.3-33.el8.x86_64  1/1

  Running scriptlet: vsftpd-3.0.3-33.el8.x86_64  1/1

  Verifying: vsftpd-3.0.3-33.el8.x86_64  1/1

  

Installed:

  vsftpd-3.0.3-33.el8.x86_64

  

Complete!

  1. 환경설정

# config 수정

[opc@ftp-test ~]$ sudo vi /etc/vsftpd/vsftpd.conf

  

# 12번째 라인

anonymous_enable=NO # yes -> no 로 변경

# 익명 유저 로그인을 차단합니다. YES 되어있을 경우 아무나 접속할 수 있으므로 보안에 취약

  

# 100번째 라인  

chroot_local_user=YES  [ # 주석 제거하거나 라인 추가 ]

# 일반계정의 유저 홈 디렉토리에서 상위 폴더로 이동하는 것을 제한합니다.

  

# 추가

pasv_enable=YES  # 패시브 모드 활성화

pasv_min_port=50001 # 접속 포트 설정의 최소 범위 (위 포트 범위 내에서 임의 설정 가능)

pasv_max_port=50005 # 접속 포트 설정의 최대 범위 (위 포트 범위 내에서 임의 설정 가능)

  

allow_writeable_chroot=YES # 일반계정 유저에 홈디렉토리에 쓰기 권한이 있을 경우 해당 옵션을 꼭 주어야 합니다  

# 안 할 경우 : 500 OOPS: vsftpd: refusing to run with writable root inside chroot()

  

pasv_address={FTP Server IP }

[ Passive 모드의 특징 ]

- PC 클라이언트에서 서버 쪽으로 21번 포트 통신 응답을 시도합니다.

- 서버 측에서 응답을 받을 경우 서버에서 사용할 두 번째 포트(1024~65535 포트)를 알려줍니다.

- PC 클라이언트는 다른 포트를 열어 서버가 알려준 두 번째 포트로 접속을 시도하고 데이터를 전송합니다.

- 하지만 서버에서 모든 두번째 포트(1024~65535 포트)를 개방하고 알려야 하는 문제가 있지만 접속 범위를 설정하여 문제를 해결할 수 있습니다.

  1. vsftpd 활성화 및 서비스 구동

# 부팅 시 자동 활성화

[opc@ftp-test ~]$ sudo systemctl enable vsftpd

Created symlink /etc/systemd/system/multi-user.target.wants/vsftpd.service → /usr/lib/systemd/system/vsftpd.service.

  

# 서비스 시작

[opc@ftp-test ~]$ sudo systemctl start vsftpd.service

  

# 구동 확인

[opc@ftp-test ~]$ ps -ef | grep vsftpd

root   49868   1  0 08:01 ?00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

opc50049   12549  0 08:02 pts/000:00:00 grep --color=auto vsftpd

  1. 방화벽 설정

# 방화벽 port 추가

[opc@ftp-test ~]$ sudo firewall-cmd --permanent --zone=public --add-port=21/tcp

success

[opc@ftp-test ~]$ sudo firewall-cmd --permanent --zone=public --add-port=50001-50005/tcp

success

  
  

# 방화벽 리로드

[opc@ftp-test ~]$ sudo firewall-cmd --reload

success

  
  

# 적용 확인

[opc@ftp-test ~]$ sudo firewall-cmd --list-all | egrep "21|5000"

  ports: 21/tcp 50001-50005/tcp

  1. 계정 설정

# User 생성

[opc@ftp-test ~]$ sudo useradd ftptest

  

# User 패스워드 설정

[opc@ftp-test ~]$ sudo passwd ftptest

Changing password for user ftptest.

New password:

Retype new password:

passwd: all authentication tokens updated successfully.

  

# 업로드를 위한 쓰기 권한 부여

[opc@ftp-test ~]$ sudo chmod 711 /home/ftptest/

  

# 디렉토리 권한 확인

[opc@ftp-test ~]$ ls -al /home | grep ftptest

drwx--x--x.  2 ftptest ftptest  62 Oct  2 09:46 ftptest

  1. FTP 업로드 공간 변경
  • 홈 경로 변경

[opc@ftp-test /]$ sudo vi /etc/passwd

#ftptest:x:1001:1001::/home/ftptest:/bin/bash

ftptest:x:1001:1001::/ftp:/bin/bash


에러

  1. 업로드 디렉토리 변경 후 553 Could not create file 발생 할 경우
  • 증상 : 업로드 시 553 Could not create file 발생
  • 조치방법
[root@ftp-test /]# cat /etc/sysconfig/selinux

  

# 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 three values:

# targeted - Targeted processes are protected,

# minimum - Modification of targeted policy. Only selected  processes are protected.

# mls - Multi Level Security protection.

SELINUXTYPE=targeted

# 방법 1 ( 재기동 필요)

SELINUX=enforcing 을 disabled로 변경

# 방법 2

sudo setsebool -P allow_ftpd_full_access on

  1. 접속하고 바이너리 모드로 접속하고 업로드 하면 나는 에러

- 증상 : ftp 접속 후 바이너리 모드로 변경 시

- 조치방법


ftp> bi

200 Switching to Binary mode.

ftp> put duosftp.dll

200 PORT command successful. Consider using PASV.

425 Failed to establish connection.

  

# 변경 전 옵션

[opc@ftp-test ~]# getsebool -a | grep ftp

ftpd_anon_write --> off

ftpd_connect_all_unreserved --> off

ftpd_connect_db --> off

ftpd_full_access --> off

ftpd_use_cifs --> off

ftpd_use_fusefs --> off

ftpd_use_nfs --> off

ftpd_use_passive_mode --> off

httpd_can_connect_ftp --> off

httpd_enable_ftp_server --> off

tftp_anon_write --> off

tftp_home_dir --> off

  

# ftpd_full_access을 on으로 바꿔주는 옵션

setsebool allow_ftpd_full_access on

  

# 변경 후 확인

[opc@ftp-test ~]# getsebool -a | grep ftp

ftpd_anon_write --> off

ftpd_connect_all_unreserved --> off

ftpd_connect_db --> off

ftpd_full_access --> on

ftpd_use_cifs --> off

ftpd_use_fusefs --> off

ftpd_use_nfs --> off

ftpd_use_passive_mode --> off

httpd_can_connect_ftp --> off

httpd_enable_ftp_server --> off

tftp_anon_write --> off

tftp_home_dir --> off


* setsebool 명령어란?

setsebool 는 현재 상태를 설정해주는 특정 selinux의 boolean 이나 boolean 리스트이다. 1은 사용가능, 0은 사용불가능이다.

selinux 정책으로 사용되는 기능들을 setsebool을 통하여 끄고 킬 수 있는 명령어이다.

NAME

   setsebool - set SELinux boolean value

  

SYNOPSIS

   setsebool [ -PV] boolean value | bool1=val1 bool2=val2 ...

  

DESCRIPTION

   setsebool  sets  the current state of a particular SELinux boolean or a

   list of booleans to a given value. The value may be 1 or true or on  to

   enable the boolean, or 0 or false or off to disable it.