1. 程式人生 > >CentOS6.5配置vsftpd

CentOS6.5配置vsftpd

一、環境

1.1 虛擬機器工具 VMware® Workstation 12 Pro  12.1.1 build-3770994

1.2 終端 SecureCRT

1.3 Linux系統 CentOS 6.5

1.3.1 Linux系統版本資訊檢視

1、uname -a

[[email protected] ~]$ uname -a
Linux localhost.localdomain 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

2、 cat /proc/version

[[email protected] ~]$ cat /proc/version
Linux version 2.6.32-431.el6.x86_64 ([email protected]) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) ) #1 SMP Fri Nov 22 03:15:09 UTC 2013

3、cat /etc/issue

[[email protected] ~]$ cat /etc/issue
CentOS release 6.5 (Final)
Kernel \r on an \m

4、 cat /etc/redhat-release

[[email protected] ~]$ cat /etc/redhat-release
CentOS release 6.5 (Final)

二、安裝

2.1 檢視是否安裝ftp伺服器

[[email protected] ~]$ rpm -qa|grep vsftp
vsftpd-2.2.2-24.el6.x86_64

2.2 若未安裝則進行安裝 切換到root 使用者 進行 安裝    yum install vsftpd -y

我的已安裝好,則顯示如下。若第一次安裝,見Completed則安裝完畢

[[email protected] ~]# yum install vsftpd -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.shu.edu.cn
 * updates: mirrors.163.com
Setting up Install Process
Package vsftpd-2.2.2-24.el6.x86_64 already installed and latest version
Nothing to do

 2.3 檢視安裝的vsftpd

[[email protected] ~]# whereis vsftpd
vsftpd: /usr/sbin/vsftpd /etc/vsftpd /usr/share/man/man8/vsftpd.8.gz

2.4 進入到vsftpd的配置資料夾中,配置檔案為 vsftpd.conf

[[email protected] ~]# cd /etc/vsftpd/
[[email protected] vsftpd]# ls
chroot_list  ftpusers  user_list  vsftpd.conf  vsftpd_conf_migrate.sh
[[email protected] vsftpd]#

2.5 編輯 vsftpd.conf檔案,進行如下配置

#anonymous_enable=YES 改成 anonymous_enable=NO

檔案末尾新增:userlist_deny=NO 僅允許user_list的使用者訪問ftp伺服器

放開下面的註釋

chroot_local_user=YES chroot_list_enable=YES # (default follows) chroot_list_file=/etc/vsftpd/chroot_list

# 使用者登入FTP伺服器後是否具有訪問自己目錄以外的其他檔案的許可權 # 設定為YES時,使用者被鎖定在自己的home目錄中,vsftpd將在下面chroot_list_file選項值的位置尋找chroot_list檔案 # 必須與下面的設定項配合 #chroot_list_enable=YES # 被列入此檔案的使用者,在登入後將不能切換到自己目錄以外的其他目錄

#chroot_list_file=/etc/vsftpd/chroot_list

# 從而有利於FTP伺服器的安全管理和隱私保護。此檔案需自己建立

cd /etc/vsftpd/

touch chroot_list

新建使用者ftpuser

useradd ftpuser

passwd testacc

寫入ftpuser到user_list、chroot_list中

echo ftpuser>> /etc/vsftpd/user_list

echo ftpuser>> /etc/vsftpd/chroot_list

# 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
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
#
# The target log file can be vsftpd_log_file or xferlog_file.
# This depends on setting xferlog_std_format parameter
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
#
# The name of log file when xferlog_enable=YES and xferlog_std_format=YES
# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
#xferlog_file=/var/log/xferlog
#
# Switches between logging into vsftpd_log_file and xferlog_file files.
# NO writes to vsftpd_log_file, YES to xferlog_file
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().
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. To listen on IPv4 and IPv6
# sockets, 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
tcp_wrappers=YES
userlist_deny=NO

2.6 編輯防火牆

在 /etc/sysconfig/iptables  中 加入

-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT

重啟防火牆

service iptables restart

[[email protected] vsftpd]# cd /etc/sysconfig
[[email protected] sysconfig]# ls
atd         console    htcacheclean  ip6tables-config  irqbalance  netconsole       ntpd        readahead      sandbox        snmptrapd               system-config-firewall.old
auditd      cpuspeed   httpd         ip6tables.old     kdump       network          ntpdate     readonly-root  saslauthd      sshd                    system-config-users
authconfig  crond      i18n          iptables          kernel      networking       prelink     rngd           selinux        sysstat                 udev
cbq         firstboot  init          iptables-config   keyboard    network-scripts  quota_nld   rsyslog        smartmontools  sysstat.ioconf          wpa_supplicant
clock       grub       ip6tables     iptables.old      modules     nspluginwrapper  raid-check  samba          snmpd          system-config-firewall
[[email protected] sysconfig]# vim iptables

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

2.7 編輯SElinux

SELINUX=disabled

檢視SELinux 的狀態

[[email protected] vsftpd]# getsebool ftpd_disable_trans

Error getting active value for ftpd_disable_trans

[[email protected] vsftpd]# sestatus -b | grep ftp

allow_ftpd_anon_write                      off

allow_ftpd_full_access                      off

allow_ftpd_use_cifs                        off

allow_ftpd_use_nfs                          off

ftp_home_dir                                off

ftpd_connect_db                            off

ftpd_use_fusefs                            off

ftpd_use_passive_mode                      off

httpd_enable_ftp_server                    off

tftp_anon_write                            off

tftp_use_cifs                              off

tftp_use_nfs                                off

結果如上, ftp_home_dir off,即SE關閉了ftp主目錄,如下,將其設定為on

[[email protected] vsftpd]# setsebool -P ftp_home_dir on

說明:-P表示永久設定,不用每次開機後都重新設定。

[[email protected] sysconfig]# vim /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=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

2.8 chkconfig  vsftpd on 設定vsftpd自啟動

2.9 啟動vsftpd

service vsftpd restart