一,基本配置和本地用户登录
1,卸载
apt-get remove --purge vsftpd
2,安装
apt-get install vsftpd
3,配置
cp /etc/vsftpd.conf /etc/vsftpd.conf.back vim /etc/vsftpd.conf
内容如下
# Example config file /etc/vsftpd.conf # # 开IPV4 listen=YES listen_ipv6=NO # # Allow anonymous FTP? (Disabled by default). anonymous_enable=NO # # Uncomment this to allow local users to log in. local_enable=YES local_root=/home/ftpuser # # 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 # # Activate directory messages - messages given to remote users when they # go into a certain directory. dirmessage_enable=YES # # If enabled, vsftpd will display directory listings with the time # in your local time zone. The default is to display GMT. The # times returned by the MDTM FTP command are also affected by this # option. use_localtime=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 #被动模式 pasv_enable=YES pasv_min_port=30000 pasv_max_port=31000 # # This option specifies the location of the RSA certificate to use for SSL # encrypted connections. rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key ssl_enable=NO # # Uncomment this to indicate that vsftpd use a utf8 filesystem. #utf8_filesystem=YES #下面是chroot部分 chroot_local_user=YES chroot_list_enable=YES chroot_list_file=/etc/vsftpd.chroot_list allow_writeable_chroot=YES secure_chroot_dir=/var/run/vsftpd/empty # vsftpd在安装的时候自动建立了/etc/pam.d/vsftpd作为认证文件,我们拷贝成vsftpd.virtual使用 pam_service_name=vsftpd.virtual
4,创建ftp系统用户并配置密码
useradd -m ftpuser -d /home/ftpuser -s /sbin/nologin passwd ftpuser
实际上,安装vsftp的时候已经自动建立ftp系统用户,也可以使用这个用户
5,设置 ftpuser 的登录认证方式
修改PAM配置 /etc/pam.d/vsftpd.virtual
将auth required pam_shells.so修改为->auth required pam_nologin.so
然后就是怎么也登录不上去,提示认证失败
使用下面方法解决
mkdir /home/ftpuser/pub chmod a-w /home/ftpuser && chmod 777 -R /home/ftpuser/pub
系统用户ftpuser的bash,设置成/sbin/nologin ,不能登录系统,目前认为同时也不能登录ftp,修改其bash后都可以登录
usermod -s /bin/bash ftpuser
6,开机启动
systemctl enable vsftpd
重启和查看状态
service vsftpd restart
service vsftpd status
追踪vsftpd状态,会提示登录失败或者成功,用于调试
tail -f /var/log/vsftpd.log
7,遇到的问题:vsftpd启动不了,总是退出
原因:复制过一些配置到/etc/vsftpd.conf里面,可能是由于格式的原因导致vsftpd不能正常读取,而导致启动失败
二,虚拟用户
虚拟用户为了解决,多用户登录时,要建一堆系统用户的麻烦。我们用多个虚拟用户对应一个系统用户,登录时使用各自的虚拟用户,方便管理。
开启了虚拟用户后,原系统用户也可以使用,只要对应的认证方式还存在于/etc/pam.d/vsftpd.virtual
/etc/vsftpd.conf里面关于虚拟用户的部分,复制到上面配置的后面
#启用虚拟用户。默认值为NO。 guest_enable=YES #用来映射虚拟用户的系统帐户。默认值为ftp。 guest_username=ftpuser #虚拟用户使用本地用户的权限 #当该参数激活(YES)时,虚拟用户使用与本地用户相同的权限。当此参数关闭(NO)时,虚拟用户使用与匿名用户相同的权限。默认情况下此参数是关闭的(NO)。 #如果不使用YES则不能登录,使用YES后可以在每个虚拟用户名的配置文件里面改权限 virtual_use_local_privs=YES #虚拟用户配置文件目录 user_config_dir=/etc/vsftpd_conf #下面的选项表示启用白名单 userlist_enable=YES userlist_deny=NO
1,创建文本格式的用户名、密码列表
首先需要建立一个文本格式的用户名/密码列表文件,奇数行为用户名,偶数行为上一行中用户名所对应的密码
例如:添加两个用户ftpread、ftpdown,密码分别为ftpread123、ftpdown456执行以下的操作:
touch /etc/vsftpd.user vim /etc/vsftpd.user ftpread ftpread123 ftpdown ftpdown456
2,安装 db-util,使用文本文件,产生认证的db文件
apt-get install db-util db_load -T -t hash -f /etc/vsftpd.user /etc/vsftpd_db.db file /etc/vsftpd_db.db /etc/vsftpd.db: Berkeley DB (Hash, version 9, native byte-order) #修改数据文件访问权限 chmod 600 /etc/vsftpd_db.db
3,继续修改PAM配置 /etc/pam.d/vsftpd.virtual,在文件头部添加内容
auth sufficient /lib/x86_64-linux-gnu/security/pam_userdb.so db=/etc/vsftpd_db
account sufficient /lib/x86_64-linux-gnu/security/pam_userdb.so db=/etc/vsftpd_db
注意这里使用的是 sufficient,如果使用required,则无论如何也通不过认证
经过试验,影响认证的两个/etc/vsftpd.conf文件配置项还有
virtual_use_local_privs=YES
chroot_list_enable=YES 并且/etc/vsftpd.chroot_list要加入虚拟用户名
如果有一个改成NO,则不能登录成功
4,vim /etc/vsftpd.chroot_list,写入如下内容。这两个虚拟用户可以进入到上层目录。如果不加入则不能登录成功。
ftpread
ftpdown
5,在虚拟用户配置文件目录/etc/vsftpd_conf下建立文件名ftpread,与虚拟用户名一致
vim /etc/vsftpd_conf/ftpread
内容是
#虚拟用户主目录 local_root=/home/ftpuser #vsftpd主配置文件中已规定虚拟用户权限与匿名用户一致,因此以下针对匿名用户的权限配置即为虚拟用户的权限 #写权限,总开关。不打开则上传,创建目录,删除文件都无法生效 write_enable=NO #下载权限 anon_world_readable_only=YES #上传权限 anon_upload_enable=NO #创建目录权限 anon_mkdir_write_enable=NO #删除,重命名目录和文件 anon_other_write_enable=NO
使用相同的配置制作/etc/vsftpd_conf/ftpdown
cp /etc/vsftpd_conf/ftpread /etc/vsftpd_conf/ftpdown
6,更改用户密码的方法
1),修改里对应的密码
vim /etc/vsftpd.user
2),重新生成数据库文件
db_load -T -t hash -f /etc/vsftpd.user /etc/vsftpd_db.db
3),这样客户端在使用原密码访问的时候会显示530未登录
这样最终形成了3个用户,虚拟用户ftpread用于看图,虚拟用户ftpdown用于下载,系统用户ftpuser用于管理
三,注意问题
1,有文章说/etc/vsftpd.ftpusers是全局黑名单,但是经过我试验一点效果也没有。可能是因为在/etc/pam.d/vsftpd.virtual里面这一行被注释掉了。
#auth required pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeed
最后还是使用/etc/vsftpd.user_list,配合
userlist_enable=YES
userlist_deny=NO
进行的登录用户名的控制。用户名可以是是系统用户名,也可以是虚拟用户名。对两种用户名都有效。
我的/etc/vsftpd.user_list内容:
ftpread
ftpdown
ftpuser
四,文章参考
1,在Ubuntu 18.04 中安装 Vsftpd
https://www.jianshu.com/p/1d89b85da283
2,配置chroot_local_user与chroot_list_enable详解
https://blog.csdn.net/bluishglc/article/details/42398811
3,FTP详解及虚拟用户
https://blog.51cto.com/meiling/2071122
4,烂泥:ubuntu下vsftpd虚拟用户配置
https://www.cnblogs.com/ilanni/p/4779376.html
5,Vsftp虚拟用户配置
https://blog.csdn.net/wenshuangzhu/article/details/44078949
6,vsftpd中关于ftpusers和user_list两个文件的说明以及vsftpd.conf中的userlist_enable和userlist_deny两个配置项的解释
https://blog.csdn.net/bluishglc/article/details/42273197
7,vsftpd 使用虚拟用户及单用户多目录的配置
https://blog.51cto.com/xmomo/2074258
浙公网安备 33010602011771号