文章目录
- 1. 安装vsftpd
- 2. 配置权限文件
- 3. 新建用户
- 4. 测试连接(filezilla)
- 4.1 500 OOPS: vsftpd: refusing to run with writable root inside chroot()
- 4.2 使用mount将其他位置的数据放在该用户目录下,使该用户可访问该数据
1. 安装vsftpd
检查是否安装了Vsftpd
rpm -qa | grep vsftpd
如果没有安装使用下面命令安装
sudo apt-get install vsftpd
启动vstfpd服务
/bin/systemctl start vsftpd.service
/bin/systemctl restart vsftpd.service
2. 配置权限文件
sudo vi /etc/vsftpd.conf
注意下面取消注释的部分
listen=NO
listen_ipv6=YES
anonymous_enable=NO
local_enable=YES
write_enable=NO
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO
utf8_filesystem=YES
更多参数解释:
https://www.cnblogs.com/fly-allblue/p/3569252.html
编辑完成之后需要重启vsftpd服务
/bin/systemctl restart vsftpd.service
3. 新建用户
sudo groupadd ftpusers //创建ftpusers用户组
sudo useradd -m ftpuser_lxr //创建一个用户并且自动创建家目录为/home/ftpuser_lxr
usermod -G ftpusers ftpuser //将这个新用户加入到ftpusers用户组中
sudo passwd ftpuser //更改密码
mkdir /home/ftpuser_lxr/ftp //为用户添加一个具有一定权限的文件夹
chmod 777 -R /home/ftpuser_lxr/ftp //新建一个pub目录用于存放文件,并且赋予全部权限
usermod -s /sbin/nologin ftpuser //限制用户登录方式;限制用户username只能通过ftp登陆,而不能直接登陆服务器
4. 测试连接(filezilla)
4.1 500 OOPS: vsftpd: refusing to run with writable root inside chroot()
连接报错原因:从2.3.5之后,vsftpd增强了安全检查,如果用户被限定在了其主目录下,则该用户的主目录不能再具有写权限了!如果检查发现还有写权限,就会报该错误。
解决方法:
sudo vim /etc/vsftpd.con
在末尾添加
allow_writeable_chroot=YES
4.2 使用mount将其他位置的数据放在该用户目录下,使该用户可访问该数据
sudo mount --bind source_file target_fileplace
也可以使用chmod改变数据的权限,使其他人只有读权限
sudo chmod 752 source_file