安装 vsftpd
关闭SELinux
[root@localhost ~]# vim /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=disabled
# SELINUXTYPE= can take one of three values:#     targeted - Targeted processes are protected,#     minimum - Modification of targeted policy. Only selected processes are protected. #     mls - Multi Level Security protection.SELINUXTYPE=targeted
检查是否已安装
[root@localhost ~]# rpm -qa | grep vsftpd
如果无,则安装
[root@localhost ~]# yum -y install vsftpd
...
...
已安装:  vsftpd.x86_64 0:3.0.2-28.el7                                                  完毕![root@localhost ~]#
如果有,则更新
[root@localhost ~]# yum -y update vsftpd
添加一个ftp的用户,用此用户来管理ftp服务器
[root@localhost ~]# useradd ftpuser
这样一个用户建完,可以用这个登录,记得用普通登录不要用匿名了。登录后默认的路径为 /home/ftpuser
设置密码
[root@localhost ~]# passwd ftpuser
修改/home/ftpuser目录权限
[root@localhost ~]# chmod 755 /home/ftpuser
创建chroot_list文件
[root@localhost ~]# cd /etc/vsftpd/
[root@localhost ~]# touch chroot_list
开放防火墙端口
[root@localhost ~]# vim /etc/sysconfig/iptables
添加一下
-A INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT-A INPUT -p tcp -m state --state NEW -m tcp --dport 30000:30999 -j ACCEPT重启防火墙
[root@localhost ~]# service iptables restart
修改/etc/vsftpd/vsftpd.conf文件
[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf
修改如下
# vi /etc/vsftpd/vsftpd.conf#关闭匿名访问anonymous_enable=NO
#启用本地系统用户,包括虚拟用户local_enable=YES
#允许执行FTP命令,如果禁用,将不能进行上传、下载、删除、重命名等操作write_enable=YES
#本地用户umask值local_umask=022
dirmessage_enable=YES
#启用日志xferlog_enable=YES
xferlog_std_format=YES
#关闭ftp-data端口,相当于不使用主动模式connect_from_port_20=NO
#限制用户不能离开FTP主目录,启用并设置例外用户清单chroot_local_user=NO
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
#使用ipv4进行监听listen=YES
listen_ipv6=NO
#pam认证文件名称,位于/etc/pam.d/pam_service_name=vsftpd
#启用全局用户例外清单userlist_enable=YES
#启用tcp封装tcp_wrappers=YES
#虚拟用户权限是否与本地用户相同。为NO时,将与匿名用户的权限相同,在每个虚拟用户配置文件里设置匿名用户的选项等于虚拟用户的权限virtual_use_local_privs=NO#启用guest后,所有非匿名用户将映射到guest_username进行访问,包括本地系统用户也不能使用,并且转换成一个虚拟用户,与其他虚拟用户的配置方法一样guest_enable=NO
guest_username=ftpuser
#虚拟用户配置文件目录user_config_dir=/etc/vsftpd/vuser_conf
#启用pasv模式pasv_enable=YES
pasv_min_port=30000
pasv_max_port=30999
allow_writeable_chroot=YES
修改/etc/pam.d/vsftpd如下
#%PAM-1.0session    optional     pam_keyinit.so    force revokeauth required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
auth       required	pam_nologin.so#auth       required	pam_shells.soauth       include	password-authaccount    include	password-authsession    required     pam_loginuid.sosession    include	password-auth重启ftp服务器
[root@localhost ~]# service vsftpd restart
至此,一个简单的vsftp服务器搭建完成