在CentOS系统中,使用vsftpd(Very Secure FTP Daemon)可以限制用户访问。以下是一些常见的方法:
首先,确保你已经安装了vsftpd。如果没有安装,可以使用以下命令进行安装:
sudo yum install vsftpd
编辑vsftpd的配置文件 /etc/vsftpd/vsftpd.conf:
sudo vi /etc/vsftpd/vsftpd.conf
你可以使用 chroot 来限制用户只能访问他们的主目录。找到并修改以下配置:
chroot_local_user=YES
allow_writeable_chroot=YES
如果你只想允许特定的用户访问FTP服务器,可以使用 userlist_enable 和 userlist_file 配置项。首先创建一个用户列表文件:
sudo vi /etc/vsftpd/user_list
在文件中添加允许访问的用户:
user1
user2
然后在配置文件中启用用户列表并指定文件路径:
userlist_enable=YES
userlist_file=/etc/vsftpd/user_list
userlist_deny=NO
如果你想进一步限制用户只能访问特定目录,可以使用 chroot 和 local_root 配置项。例如,限制用户只能访问 /home/user1/uploads 目录:
local_root=/home/user1/uploads
chroot_local_user=YES
allow_writeable_chroot=YES
保存并退出配置文件后,重启vsftpd服务以应用更改:
sudo systemctl restart vsftpd
确保防火墙允许FTP流量。你可以使用以下命令打开FTP端口(默认是21):
sudo firewall-cmd --permanent --add-port=21/tcp
sudo firewall-cmd --reload
如果启用了SELinux,可能需要调整相关策略以允许vsftpd正常工作。你可以临时禁用SELinux进行测试:
sudo setenforce 0
或者修改SELinux策略文件 /etc/selinux/config:
SELINUX=disabled
使用FTP客户端连接到服务器,测试配置是否生效。例如,使用 ftp localhost 连接到服务器,并尝试访问受限目录。
通过以上步骤,你可以有效地限制CentOS系统中vsftpd用户的访问权限。