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

Linux Vsftpd 500 OOPS: cannot change directory 徹底解決(SELinux 篇)

編輯:關於 Linux

錯誤現象

500 OOPS: cannot change directory:/home/ftpuser

FTP 登入成功但無法進入家目錄,純淨安裝 Vsftpd 後常見於啟用 SELinux 的 CentOS/RHEL 系統。

根本原因

SELinux 預設禁止 ftpd 存取使用者家目錄(ftp_home_dir)或要求完整存取權限(ftpd_full_access)。

一鍵修復指令

# 1. 查看當前狀態
getsebool -a | grep ftp

# 2. 啟用必要布林值(二選一或同時開啟)
setsebool -P ftp_home_dir on        # 允許 FTP 讀寫用戶家目錄
setsebool -P ftpd_full_access on    # 允許 FTP 完全存取(較寬鬆)

# 3. 驗證生效
getsebool -a | grep -E 'ftp_home_dir|ftpd_full_access'
# 輸出應為 on

# 4. 重啟服務
systemctl restart vsftpd

原理解析

布林值含義適用場景
ftp_home_dir允許 ftpd 存取 /home/username標準虛擬用戶、本地用戶家目錄
ftpd_full_access允許 ftpd 存取所有標記為 public_content_rw_t 的檔案多重掛載點、共享儲存、匿名上傳
ftpd_use_passive_mode允許被動模式連接需開啟防火牆高端口時

進階:自訂目錄標籤(不開全域布林值)

# 為特定目錄打標籤
semanage fcontext -a -t public_content_rw_t "/srv/ftp(/.*)?"
restorecon -Rv /srv/ftp
setsebool -P ftpd_full_access on

驗證測試

ftp localhost
# 登入後
ls
pwd
put test.txt

修正 SELinux 布林值後,Vsftpd 即可正常切換目錄,無需關閉 SELinux 降低系統安全性。

Copyright © Windows教程網 All Rights Reserved