温馨提示×

centos vsftp如何限制访问

小樊
39
2025-12-09 11:35:14
栏目: 智能运维

在CentOS系统中,使用vsftpd(Very Secure FTP Daemon)时,可以通过配置文件来限制用户的访问。以下是一些常见的访问限制方法:

1. 配置vsftpd.conf文件

编辑/etc/vsftpd/vsftpd.conf文件,进行相应的配置。

1.1 限制用户访问

  • chroot_local_user=YES:将本地用户锁定在其主目录中。
  • allow_writeable_chroot=YES:允许chroot环境中的用户写入其主目录。
sudo vi /etc/vsftpd/vsftpd.conf

添加或修改以下行:

chroot_local_user=YES
allow_writeable_chroot=YES

1.2 限制特定用户访问

  • userlist_enable=YES:启用用户列表。
  • userlist_file=/etc/vsftpd/user_list:指定用户列表文件。
  • userlist_deny=NO:拒绝不在用户列表中的用户。

/etc/vsftpd/user_list文件中添加需要限制的用户:

sudo vi /etc/vsftpd/user_list

添加用户名:

username1
username2

然后在vsftpd.conf中添加:

userlist_enable=YES
userlist_file=/etc/vsftpd/user_list
userlist_deny=NO

1.3 限制IP访问

  • tcp_wrappers=YES:启用TCP Wrappers。
  • hosts.deny=ALL:拒绝所有IP。
  • hosts.allow=192.168.1.0/24:允许特定IP段访问。

编辑/etc/hosts.deny/etc/hosts.allow文件:

sudo vi /etc/hosts.deny

添加:

ALL
sudo vi /etc/hosts.allow

添加:

vsftpd: 192.168.1.0/24

2. 重启vsftpd服务

配置完成后,重启vsftpd服务以使更改生效:

sudo systemctl restart vsftpd

3. 验证配置

确保配置正确无误后,可以通过FTP客户端尝试连接并验证访问限制是否生效。

注意事项

  • 在进行配置更改之前,建议备份原始的vsftpd.conf文件。
  • 确保防火墙允许FTP流量(通常是21端口)。
  • 如果使用SELinux,可能需要调整相关策略以允许vsftpd正常运行。

通过以上步骤,你可以有效地限制CentOS系统中vsftpd的访问权限。

0