一、匿名开放模式(最不安全)
1、# vim /etc/vsftpd/vsftpd.conf (主配置)
anonymous_enable=YES //允许匿名访问模式anon_umask=022 //匿名用户上传文件的的umask值anon_upload_enable=YES //允许匿名用户上传文件anon_mkdir_write_enable=YES //允许匿名用户创建目录anon_other_write_enable=YES //允许匿名用户修改目录名称或删除目录
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=NO
listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
2、# systemctl restart vsftpd
3、# systemctl enable vsftpd
4、# yum install -y ftp (命令行管理工具)注:该模式默认用户为anonymous,密码为空,默认访问目录/var/ftp
5、# ftp 192.168.40.132
Connected to 192.168.40.132 (192.168.40.132).
220 (vsFTPd 3.0.2)
Name (192.168.40.132:root): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd pub
250 Directory successfully changed.
ftp> mkdir zjz1 (创建新文件夹)
257 "/pub/zjz1" created
ftp> rename zjz1 zjz2 (改名)
350 Ready for RNTO.
250 Rename successful.
ftp> rmdir zjz2 (删除)
250 Remove directory operation successful.
ftp> exit (退出)
221 Goodbye.
注:第一次做时权限不够。
解决:
1、# chown -Rf ftp /var/ftp/pub
2、# getsebool -a | grep ftp ;
# setsebool -p ftpd_full_access=on (或直接关闭selinux)
3、关闭防火墙
二、本地用户模式
1、# vim /etc/vsftpd/vsftpd.confanonymous_enable=NO //禁止匿名访问local_enable=YES //允许本地用户模式write_enable=YES //设置可写权限local_umask=022 // //本地用户创建文件的的umask值
userlist_enable=YES //启用“禁止用户名单”,名单文件为ftpusers 和 user_list
userlist_deny=YES //开启用户作用名单文件功能
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=NO
listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
2、# systemctl restart vsftpd
3、# systemctl enable vsftpd
4、# ftp 192.168.40.132
Connected to 192.168.40.132 (192.168.40.132).
220 (vsFTPd 3.0.2)
Name (192.168.40.132:root): root (被拒绝)
530 Permission denied.
Login failed.
ftp>
5、[root@localhost ~]# cd /etc/vsftpd/[root@localhost vsftpd]# lsftpusers user_list vsftpd.conf vsftpd_conf_migrate.sh
注:上面两个文件夹就是禁止名单,root被禁止对系统更安全
6、[root@localhost ~]# ftp 192.168.40.132
Connected to 192.168.40.132 (192.168.40.132).
220 (vsFTPd 3.0.2)
Name (192.168.40.132:root): cui (本地用户)
331 Please specify the password.
Password: (要密码)
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
其余同匿名模式
三、虚拟用户模式(最安全)
1、# cd /etc/vsftpd/
# ls
ftpusers user_list vsftpd.conf vsftpd_conf_migrate.sh
# vim vuser.list (创建用户数据库文件)
zhagnsan
123456 (密码)
lisi
123## (密码)2、# db_load -T -t hash -f vuser.list vuser.db (哈希加密)
3、# file vuser.db
vuser.db: Berkeley DB (Hash, version 9, native byte-order)4、# chmod 600 vuser.db
5、# rm -rf vuser.list
6、# useradd -d /var/ftproot -s /sbin/nologin virtual (创建本地用户,指定家目录,禁止本地用户登录,这个账户映射到虚拟用户)
7、# ls -ld /var/ftproot/
drwx------ 2 virtual virtual 62 Sep 15 08:17 /var/ftproot/
8、# chmod -Rf 755 /var/ftproot/
9、# vim /etc/pam.d/vsftpd.vu (PAM一组安全机制模块)
auth required pam_userdb.so db=/etc/vsftpd/vuser
account required pam_userdb.so db=/etc/vsftpd/vuser
10、# vim /etc/vsftpd/vsftpd.conf anonymous_enable=NOlocal_enable=YESguest_enable=YES //开启虚拟用户模式guest_username=virtual //指定虚拟用户账户allow_writeable_chroot=YES //允许被禁锢的ftp根目录执行写入操作,而且不拒绝用户的登录请求
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=NO
listen_ipv6=YESpam_service_name=vsftpd.vu //指定pam文件
userlist_enable=YES
tcp_wrappers=YES
11、# mkdir /etc/vsftpd/vusers_dir/
# cd /etc/vsftpd/vusers_dir/
# touch lisi
# vim zhangsan
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
12、# vim /etc/vsftpd/vsftpd.conf
anonymous_enable=NO
.....同上user_config_dir=/etc/vsftpd/vusers_dir
13、重启服务
# systemctl restart vsftpd
# systemctl enable vsftpd