通过yum安装vsftpd
yum install -y vsftpd
修改vsftpd的配置文件
vi /etc/vsftpd/vsftpd.conf
修改配置文件如下:
1.不允许匿名访问
anonymous_enable=NO
2.允许使用本地帐户进行FTP用户登录验证
local_enable=YES
3.使用户不能离开主目录
当chroot_list_enable=YES,chroot_local_user=YES时,在/etc/vsftpd.chroot_list文件中列出的用户,可以切换到其他目录;未在文件中列出的用户,不能切换到其他目录。
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
配置文件最后添加
#增加
guest_enable=YES
guest_username=www
user_config_dir=/etc/vsftpd/vuser_conf #(虚拟用户)
allow_writeable_chroot=YES
如果/etc/vsftpd/chroot_list不存在,则需要创建该文件
touch /etc/vsftpd/chroot_list
虚拟用户列表
奇行为用户名,偶行为密码
# vi /etc/vsftpd/vuser
虚拟用户认证文件
# db_load -T -t hash -f /etc/vsftpd/vuser /etc/vsftpd/vuser.db
# chmod 600 /etc/vsftpd/vuser.db
虚拟用户认证配置
vi /etc/pam.d/vsftpd
auth required /lib64/security/pam_userdb.so db=/etc/vsftpd/vuser
account required /lib64/security/pam_userdb.so db=/etc/vsftpd/vuser
虚拟用户配置文件
# mkdir /etc/vsftpd/vuser_conf/
# vi /etc/vsftpd/vuser_conf/ftpserver #文件名与对应FTP虚拟用户一致
local_root=/var/vsftp/ftpserver #虚拟用户主目录,用户和组必须指定为宿主用户vsftp
#vsftpd主配置文件中已规定虚拟用户权限与匿名用户一致,因此以下针对匿名用户的权限配置即为虚拟用户的权限
anon_umask=077
anon_world_readable_only=NO #(YES,不允许下载)
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
宿主用户
创建宿主用户,即guest_username,所有虚拟用户都是映射宿主用户的目录权限。
# useradd vsftpd
最后 :wq保存修改,重启vsftpd
systemctl restart vsftpd
设置开机自启动
systemctl enable vsftpd
开启端口
1. vi /etc/sysconfig/iptables
新增:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
2. systemctl restart iptables.service 重启