VSFTP如何拒绝上传某个具体文件

博客介绍了VSFTP中deny_file选项的使用,该选项可设置文件名(及目录名等)模式,使匹配项不可被访问。虽此选项简单,不适合用于严格访问控制,建议优先用文件系统权限,但在特定虚拟用户设置中有用,使用时需全面测试。
部署运行你感兴趣的模型镜像



deny_file
    This option can be used to set a pattern for filenames (and directory names etc.) which should not be accessible in any way. The affected items are not hidden, but any attempt to do anything to them (download, change into directory, affect something within directory etc.) will be denied. This option is very simple, and should not be used for serious access control - the filesystem's permissions should be used in preference. However, this option may be useful in certain virtual user setups. In particular aware that if a filename is accessible by a variety of names (perhaps due to symbolic links or hard links), then care must be taken to deny access to all the names. Access will be denied to items if their name contains the string given by hide_file, or if they match the regular expression specified by hide_file. Note that vsftpd's regular expression matching code is a simple implementation which is a subset of full regular expression functionality. Because of this, you will need to carefully and exhaustively test any application of this option. And you are recommended to use filesystem permissions for any important security policies due to their greater reliability. Example: deny_file={*.mp3,*.mov,.private}

VSFTP拒绝上传具体文件的方法:

deny_file={*.mp3,*.mov,.private}

    Default: (none) 

例如 deny_file={index.html,index.htm}

您可能感兴趣的与本文相关的镜像

Yolo-v8.3

Yolo-v8.3

Yolo

YOLO(You Only Look Once)是一种流行的物体检测和图像分割模型,由华盛顿大学的Joseph Redmon 和Ali Farhadi 开发。 YOLO 于2015 年推出,因其高速和高精度而广受欢迎

<think>嗯,用户需要了解vsftpd如何拒绝特定文件后缀的设置方法。根据之前的对话历史和提供的引用内容,这属于FTP服务器配置的技术问题。 用户可能是一位系统管理员或者开发人员,正在配置vsftpd服务器时遇到了安全需求,需要阻止用户上传或下载某些类型的文件(比如可执行文件)。用户引用的资料中提到了vsftpd的基础配置,但没有直接涉及文件后缀过滤功能。 从技术实现角度看,vsftpd原生并不支持直接通过配置参数过滤文件后缀。不过可以通过两种思路解决: 1)利用hide_file指令隐藏特定后缀文件(但实际文件仍存在) 2)更彻底的做法是通过iptables防火墙过滤FTP-DATA通道传输的特定后缀名流量 用户似乎对Linux系统比较熟悉(能提供配置文件路径),所以应该能理解iptables方案。但考虑到用户提问的焦点是"vsftpd设置方法",可能更希望得到基于服务本身的解决方案。因此需要重点说明hide_file的局限性——它只是隐藏而非真正阻止传输。 在回复中需要明确区分两种方案的适用场景: - 如果只是希望用户不可见,用hide_file - 如果要彻底阻断传输,必须配合防火墙 另外注意到引用[3]提到Linux文件名规范,需要提醒用户过滤规则要区分大小写(如*.exe和*.EXE都要考虑),这个细节很容易被忽略但实际部署时会出问题。最后补充的"注意事项"特别重要,因为文件过滤可能影响业务功能,必须强调测试环节。 </think>根据vsftpd的功能限制,原生配置**不支持直接拒绝特定后缀文件传输**,但可通过以下两种方案实现类似效果: --- ### 方案一:使用 `hide_file` 隐藏特定后缀文件(伪拒绝)[^1] **原理**:使客户端无法看到/访问指定后缀文件(实际文件仍存在服务器) 1. **修改配置文件**: ```bash sudo vim /etc/vsftpd/vsftpd.conf ``` 2. **添加规则**(例:隐藏所有 `.exe` 和 `.sh` 文件): ```ini # 隐藏文件规则(支持通配符) hide_file={*.exe,*.sh} # 确保启用隐藏功能 force_dot_files=NO # 禁止显示隐藏文件(增强效果) ``` 3. **重启服务**: ```bash sudo systemctl restart vsftpd ``` > ⚠️ **局限性**:用户仍可通过**精确文件名**直接访问文件(如输入完整路径 `ftp://server/secret.exe`) --- ### 方案二:结合防火墙拦截数据传输(彻底阻断)[^2] **原理**:使用 `iptables` 在传输层阻断含特定后缀的FTP-DATA连接 1. **创建防火墙规则**(阻断 `.exe` 文件传输): ```bash sudo iptables -A OUTPUT -p tcp --dport 20 -m string --string ".exe" --algo bm -j DROP ``` 2. **持久化规则**(CentOS/RHEL): ```bash sudo service iptables save ``` > ✅ **优势**:真正阻止文件传输 > ❗ **注意**:需配合 `vsftpd` 的被动端口范围设置: > ```ini > pasv_min_port=60000 > pasv_max_port=61000 > ``` --- ### 补充策略:文件上传后自动删除 通过 `inotifywait` 监控上传目录并删除目标文件: ```bash #!/bin/bash inotifywait -m -r -e create /var/ftp/upload/ | while read path action file; do if [[ "$file" =~ \.(exe|sh)$ ]]; then rm -f "$path$file" echo "[$(date)] 删除危险文件: $file" >> /var/log/ftp_clean.log fi done ``` --- ### 注意事项 1. 方案二需开启 `ip_nat_ftp` 模块(加载命令:`sudo modprobe ip_nat_ftp`) 2. 文件后缀名匹配**区分大小写**(建议同时过滤 `.EXE`) 3. 方案三需通过 `crontab` 或 `systemd` 实现后台监控 > 📌 **推荐组合**:方案一(快速隐藏)+ 方案二(彻底阻断) + 日志审计 > 配置后可通过 `ftp> put test.exe` 测试效果,客户端应返回 `553 Could not create file` 错误。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值