리눅스 초급/FTP
[FTP](3) FTP 설치 및 설정
알 수 없는 사용자
2016. 4. 28. 11:24
1. vsFTP 설치
[root@vilinux-03 ~]# yum -y install vsftpd
-> yum 명령으로 간단하게 vsftpd 설치가 가능하다.
[root@vilinux-03 ~]# rpm -qa | grep ftp
ftp-0.17-54.el6.x86_64
vsftpd-2.2.2-14.el6_7.1.x86_64
-> vsftp가 잘 설치된 것을 볼 수 있다.
2. /etc/vsftp/vsftpd.conf 설정하기
-> 익명의 사용자가 접속할 수 있는지 설정한다. 기본값은 YES로 보안을 위해 NO로 바꿔준다.
-> local 사용자가 사용가능한지 설정해준다.
-> 접속한 사용자가 write할 수 있는지 설정한다.
-> 파일을 업로드하거나 받았을 때 기본 umask값
-> 위의 anonymous_enable 과 연관된 설정으로 익명의 사용자가 업로드 할 수 있게 할 것인지 설정한다.
-> 사용자가 특정 디렉토리에 접근하였을 때 메시지를 보여준다.
-> vsftp의 로그파일로 오류가 있거나 작업을 하였을 때 확인할 수 있다.
xferlog_file=/var/log/xferlog
-> vsftp의 로그파일 경로
-> local 사용자가 접근했을 때 chroot으로 상위 디렉토리에 접근하지 못하게 막는다. 즉 계정의 홈디렉토리를 최상위로 설정하여 상위 디렉토리에 접근 할 수 없다.
-> ftp 요청을 받기 위한 설정
3. vsftp 잘 작동하는지 확인
3-1. 실습을 위해서 방화벽을 꺼준다.(실습을 위해 그냥 다꺼버리는게 속편합니다)
[root@vilinux-03 /]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
3-2. selinux도 꺼준다.(selinux enabled 안바꿨다가 동작하지 않았던 경험이..)
[root@vilinux-03 /]# cat /etc/sysconfig/selinux | grep disabled
# disabled - No SELinux policy is loaded.
SELINUX=disabled
[root@vilinux-03 /]# cat /etc/selinux/config | grep disabled
# disabled - No SELinux policy is loaded.
SELINUX=disabled
3-3. 실습하기 위해 yong 유저를 만들고 test! 파일을 생성해준다.
[root@vilinux-03 /]# cd /home/yong
[root@vilinux-03 yong]# ls
test!
3-4. 01번 클라이언트로 접속했을 때 test! 파일이 보이는 것을 확인할 수 있다.
[root@vilinux-01 ~]# ftp
ftp> open
(to) 14.0.81.236
Connected to 14.0.81.236 (14.0.81.236).
220 (vsFTPd 2.2.2)
Name (14.0.81.236:root): yong
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/home/yong"
ftp> ls
227 Entering Passive Mode (14,0,81,236,126,245).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 0 Apr 28 02:38 test!
226 Directory send OK.
*실습을 위해 vsftpd.conf 에서 chroot_local_user=NO로 바꿨습니다.
3-5. 550 Failed to change directory 오류
ftp> cd /home/yong
550 Failed to change directory.
해결
chroot_local_user=NO
여기서 중요한 문제가 발생한다. chroot 항목을 NO로 풀어버리면 다른 사용자가 상위 디렉토리를 활보하고 다니게 된다. 보안상 굉장히 위험하다.
3-6. chroot 응용법
다른 사용자는 막아두고 yong만 상위 디렉토리를 이용하게 하고 싶다면 chroot_list 에 yong 을 적어놓고 아래와 같이 설정합니다.
chroot_local_user=YES
chroot_list_enable=YES
[root@vilinux-03 yong]# cat /etc/vsftpd/chroot_list
#root
yong
[root@vilinux-01 ~]# ftp
ftp> open
(to) 14.0.81.236
Connected to 14.0.81.236 (14.0.81.236).
220 (vsFTPd 2.2.2)
Name (14.0.81.236:root): yong
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/home/yong"
ftp> ls
227 Entering Passive Mode (14,0,81,236,44,106).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 0 Apr 28 02:38 test!
226 Directory send OK.
[root@vilinux-01 ~]# ftp
ftp> open 14.0.81.236
Connected to 14.0.81.236 (14.0.81.236).
220 (vsFTPd 2.2.2)
Name (14.0.81.236:root): won
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pw
257 "/"
ftp> cd /home/won
550 Failed to change directory.
chroot_list에 설정해둔 yong 사용자는 다른 디렉토리를 사용할 수 있고 list에 없는 won 사용자는 다른 디렉토리 이동이 안되는 것을 볼 수 있습니다.
* 다음 글에선 passvie mode와 active mode의 차이점을 알아보겠습니다!