Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

Linux FTP 無法刪除靜態 HTML 檔案:權限不一致解決方案

編輯:關於伺服器

原因分析

FTP 用戶 (如 ftpuser) 與 Web 伺服器進程用戶 (如 www-data, nginx) 不同,導致 Web 產生的靜態檔案擁有者為 Web 用戶,FTP 用戶無寫入/刪除權限。

快速修復

# 進入網站根目錄
cd /home/web

# 遞歸授予所有者/群組/其他 完整權限 (臨時方案,生產環境請精確控制)
chmod 777 html -Rf

# 進入目錄再次確保
cd html
chmod 777 * -Rf

規範長效方案

  1. 統一用戶組:將 FTP 用戶與 Web 用戶加入同一群組 (如 webgroup),目錄設定 setgid 並授予群組寫入權限。
    groupadd webgroup
    usermod -a -G webgroup ftpuser
    usermod -a -G webgroup www-data
    chown -R :webgroup /home/web/html
    chmod -R 2775 /home/web/html  # setgid + 群組寫入
  2. ACL 精細控制:
    setfacl -R -m u:ftpuser:rwx /home/web/html
    setfacl -R -d -m u:ftpuser:rwx /home/web/html  # 預設 ACL
  3. PHP/FPM 以 FTP 用戶身分運行 (pool 設定 user = ftpuser),但需注意安全隔離。

安全提醒

chmod 777 會暴露檔案給所有本地用戶,僅限臨時救援使用,完成後務必恢復最小權限原則。

Copyright © Windows教程網 All Rights Reserved