Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Vsftpd 553 Could Not Create File:SELinux 布林值一鍵解鎖

編輯:Linux 系統常見問題解答

Vsftpd 上傳報 553 Could not create file,權限、擁有者、磁碟空間全正常?九成是 **SELinux 阻擋 ftp 寫入**。本文 30 秒定位、一鍵解鎖、永久生效。

現場還原

# 客戶端
ftp> put test.txt
local: test.txt remote: test.txt
553 Could not create file

# 伺服器端
ls -ld /var/ftp/pub
# drwxr-xr-x 2 ftp ftp 4096 Mar 20 10:00 /var/ftp/pub
# 權限、擁有者全對,磁碟也有空間

根因:SELinux 布林值預設關閉

getsebool -a | grep ftp
# allow_ftpd_anon_write --> off
# allow_ftpd_full_access --> off   ← 關鍵!
# ftpd_connect_db --> off
# ...

allow_ftpd_full_access 控制 ftpd 是否可**無限制讀寫**所有標準檔案類型。預設 off 導致即使 DAC 權限允許,SELinux 仍拒絕寫入。

一鍵解鎖(永久生效)

# 1. 開啟布林值(-P 寫入 policy,重啟不失效)
setsebool -P allow_ftpd_full_access on

# 2. 驗證
getsebool allow_ftpd_full_access
# allow_ftpd_full_access --> on

# 3. 重啟 vsftpd 確保生效
systemctl restart vsftpd

驗證上傳

ftp> put test.txt
200 PORT command successful
150 Ok to send data
226 Transfer complete
ftp> ls
-rw-r--r-- 1 ftp ftp 12 Mar 20 10:05 test.txt

進階:若只想開放匿名上傳

setsebool -P allow_ftpd_anon_write on
# 僅允許匿名用戶寫入標記為 public_content_rw_t 的目錄

替代方案:暫時關閉 SELinux(不建議生產)

# 暫時(重啟失效)
setenforce 0

# 永久(需重啟)
sed -i 's/^SELINUX=.*/SELINUX=permissive/' /etc/selinux/config
# 或 disabled

避坑清單

誤區正確做法
以為是 vsftpd.conf 權限設定錯DAC 權限正確時,553 多半是 SELinux
只設 setsebool allow_ftpd_full_access on 忘記 -P重啟後失效,**必加 -P**
直接關閉 SELinux失去整體防護,**精準開啟布林值**即可
目錄標籤錯誤確認 ls -Z /var/ftp/pub 顯示 public_content_rw_t 或 var_t

結語: Vsftpd 553 錯誤,檢查完 DAC 權限無果時,**直接 setsebool -P allow_ftpd_full_access on**。精準開啟 SELinux 布林值,既解決問題又保留防護,才是運維正解。

Copyright © Windows教程網 All Rights Reserved