CentOS中vsftp服務安裝、配置、卸載

1.檢查centos是否安裝vsftpd

  [root@localhost zhangzhuo]# rpm -aq vsftpd

  vsftpd-3.0.2-22.el7.x86_64  #查詢的返回結果,表明已安裝

  若要卸載Vfstpd:

    [root@localhost zhangzhuo]# rpm -e vsftpd-3.0.22-22.el7.x86_64

  由於我的vsftpd服務已搭建好,所以就不給演示刪除,但我之前配置錯誤,用此方法刪除是沒有問題的

  查看是否卸載了vsftpd:

    [root@localhost zhangzhuo]# /sbin/service vsftpd stop

    [root@localhost zhangzhuo]# /sbin/service vsftpd start   

    #在卸載vsftpd之前要 先停止vsftpd

2.安裝vsftpd

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

3.修改vsftpd.conf文件

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

  

按 Ctrl+C 複製代碼
# Example config file /etc/vsftpd/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.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
#anonymous_enable=YES
#
# Uncomment this to allow local users to log in.
# When SELinux is enforcing check for SE bool ftp_home_dir
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.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
#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
#
# 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/xferlog
#
# 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 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
#
# 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
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES
#
# 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.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES


pam_service_name=vsftpd
userlist_enable=YES
userlist_deny=NO
local_root=/var/public_root
tcp_wrappers=YES
use_localtime=YES
allow_writeable_chroot=YES
按 Ctrl+C 複製代碼

  最後一句,爲了解決“當我們限定了用戶不能跳出其主目錄之後,使用該用戶登錄FTP時遇到的錯誤”:

1 500 OOPS: vsftpd: refusing to run with writable root inside chroot ()

  這個問題發生在最新的這是由於下面的更新造成的:

1 Add stronger checks for the configuration error of running with a writeable root directory inside a chroot()

  從2.3.5之後,vsftpd增強了安全檢查,如果用戶被限定在了其主目錄下,則該用戶的主目錄不能再具有寫權限了!如果檢查發現還有寫權限,就會報該錯誤。

 要修復這個錯誤,可以用命令chmod a-w /home/user去除用戶主目錄的寫權限,注意把目錄替換成你自己的。或者你可以在vsftpd的配置文件中增加標紅的最後一句話

3.添加ftp賬戶

  爲了方便記憶,這裏設置的賬戶爲vsftpd、密碼爲123456

1 [root@localhost zhangzhuo]# useradd vsftpd -s /sbin/nologin 
2 [root@localhost zhangzhuo]# passwd vsftpd

4.編輯user_list文件,允許vsftpd訪問ftp

1 [root@localhost zhangzhuo]# vi /etc/vsftpd/user_list 
複製代碼
 1 # vsftpd userlist
 2 # If userlist_deny=NO, only allow users in this file
 3 # If userlist_deny=YES (default), never allow users in this file, and
 4 # do not even prompt for a password.
 5 # Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
 6 # for users that are denied.
 7 root
 8 bin
 9 daemon
10 adm
11 lp
12 sync
13 shutdown
14 halt
15 mail
16 news
17 uucp
18 operator
19 games
20 nobody
21 vsftpd
22 ~                                                                                      
23 ~                                                                                      
24 ~       
複製代碼

5.建立根目錄,設置訪問權限

1 [root@localhost zhangzhuo]# mkdir /var/public_root
2 [root@localhost zhangzhuo]# chown -R vsftpd /var/public_root
3 [root@localhost zhangzhuo]# chmod -R 755 /var/public_root

6.關閉防火牆或開放21端口

  ftp設置好了之後,服務啓動了但連接失敗,ftp默認是21號端口,但Linux的21端口默認是關閉的,關閉防火可以解決,但不推薦 

複製代碼
1 firewall-cmd –state ----> 查看防火牆狀態
2     service firewalld start ----> 啓動防火牆
3     service firewalld restart ----> 重啓防火牆
4     service firewalld stop -----> 關閉防火牆
5     firewall-cmd --query-port=21/tcp ----->查詢端口是否開放
6     firewall-cmd --permanent --add-port=21/tcp ----->開放21端口
7     firewall-cmd --permanent --remove-port=21/tcp ----->移除端口
8     firewall-cmd --reload  ----->重啓防火牆(修改配置後要重啓防火牆)
複製代碼

7.開啓vsftpd服務

1 [root@localhost zhangzhuo]# service vsftpd start
2 [root@localhost zhangzhuo]# systemctl status vsftpd.service #查看vsftpd服務狀態
3 [root@localhost zhangzhuo]# systemctl restart vsftpd.service #重啓vsftpd服務

8.設置開機啓動vsftpd服務

1 [root@localhost zhangzhuo]# chkconfig vsftpd on

 

至此,ftp服務就搭建起來了,可以通過物理主機的dos命令行使用"ftp linux虛擬機IP"或者FileZilla軟件進行連接測試

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章