본문 바로가기
Server/Linux

[Ubuntu] 리눅스 FTP서버 만들기(권한부여, 홈디렉토리변경,우분투)

by tyrannojung 2021. 8. 20.
반응형

 클라이언트에 열어줄 FTP 서버를 만들 필요가 있었습니다. 해서 '클라이언트가 접속 할 수 있는 계정'과 그 계정이 접근 가능한 '리눅스의 특정 폴더'를 열어 주어야 했고, 이 글은 그러한 과정에 대한 정리 내용입니다.

 

ftp 서버는 vsftpd를 사용했습니다.

 

vsftpd는 리눅스에서 동작하는 FTP 서버 프로그램으로, 안전성과, 빠른 속도 그리고 보안성이 우수한 전 세계에서 가장 많이 쓰는 FTP 서버입니다.

 

글의 진행 순서입니다.

 

1. 리눅스 계정 생성 및 루트(홈) 디렉토리 변경

2. 해당 사용자 SSH,SFTP 접근 안되게 막기

3. vsftpd 설치 및 설정

 

리눅스 계정 생성 및 루트(홈) 디렉터리 변경

 

계정 생성

 

sudo useradd mcop
sudo passwd mcop

※ 여기서 mcop를 빼고 원하는 계정 이름을 넣으면 됩니다.

 

해당 계정에 대한 루트(홈) 디렉터리 변경

 

su -
vi /etc/passwd

 

( ※ chmod a+rw mcop 처럼 기호에 맞게 해당 폴더에 접근권한을 미리 주자.)

 

 위화면의 빨간색 박스가 접속 시 시작하는 root 폴더입니다.

 공유 원하는 폴더의 경로로 수정해 줍니다. 

 

 

해당 사용자 SSH, SFTP 접근 불가 설정

 

su -
vi /etc/pam.d/sshd

 

auth required pam_listfile.so item=user sense=deny file=/etc/ssh/sshusers onerr=succeed 

(※ 위 예시처럼 맨 위 상단에 해당 코드를 붙여넣고 저장합니다.)

 

vi /etc/ssh/sshusers

 

 

위 예시 처럼 sshusers생성 후, ssh 접속을 제한할 사용자를 1줄씩 입력해 줍니다.

 

service sshd restart

 

모든 설정이 완료되었으므로 restart 해줍니다.

 

vsftpd 설치 및 설정

 

vsftpd설치

 

sudo apt-get -y install vsftpd

 

FTP 서버에 대해 클라이언트가 읽기 , 쓰기 가 포함된 '디렉토리 생성 삭제의 권한'이 필요합니다.
뿐만 아니라 FTP사용자의 상위 디렉토리 접근 차단을 하여 우리가 위에서 설정한 루트 디렉토리 안에서만 활동 가능하게 진행해야 합니다.

 

vsftpd 수정

 

su -
vi /etc/vsftpd.conf

 

수정 코드

 

# Example config file /etc/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
#
# Run standalone?  vsftpd can run either from an inetd or as a standalone
# daemon started from an initscript.
listen=NO
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
listen_ipv6=YES
#
# Allow anonymous FTP? (Disabled by default).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
#local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# If enabled, vsftpd will display directory listings with the time
# in  your  local  time  zone.  The default is to display GMT. The
# times returned by the MDTM FTP command are also affected by this
# option.
use_localtime=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
#xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd.banned_emails
#
# You may restrict local users to their home directories.  See the FAQ for
# the possible risks in this before using chroot_local_user or
# chroot_list_enable below.
#chroot_local_user=YES
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
#chroot_local_user=YES
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd.chroot_list
allow_writeable_chroot=YES
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# Customization
#
# Some of vsftpd's settings don't fit the filesystem layout by
# default.
#
# This option should be the name of a directory which is empty.  Also, the
# directory should not be writable by the ftp user. This directory is used
# as a secure chroot() jail at times vsftpd does not require filesystem
# access.
secure_chroot_dir=/var/run/vsftpd/empty
#
# This string is the name of the PAM service vsftpd will use.
pam_service_name=vsftpd
#
# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO

#
# Uncomment this to indicate that vsftpd use a utf8 filesystem.
#utf8_filesystem=YES

(필요한 부분만 주석을 해제해 주시면 간단합니다.)

 

 

위에서 중요한 부분은 

chroot_list_enable=YES

chroot_list_file=/etc/vsftpd.chroot_list

으로,

 

vsftpd.chroot_list에 있는 “특정 사용자”에 대해 접근 범위를 제한한다는 내용입니다.

 

vi /etc/vsftpd.chroot_list

 

위 예시처럼 "특정 사용자"를 1줄씩 입력해 줍니다.

 

service vsftpd restart

 

모든 설정이 완료되었으므로 restart 해줍니다.

 

 

완료

 

설정이 완료되었으면 FIleZila 같은 FTP로 접속해서 테스트를 해봅니다.

간혹 vsftpd 500 OOPS 에러가 나는 경우가 있는데, 이는 해당 폴더가 접속하려는 FTP 계정이 접근권한이 없을 때 생깁니다.

chmod a+rw mcop처럼 해당 폴더를 기호에 맞게 접근권한을 주면 됩니다.


여러 가지를 참고하여 만든 것으로 혹시라도 잘못됐거나 안 되는 점 있으면 댓글 남겨주시면 감사하겠습니다!

 

 

 

반응형

댓글