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

vsftpd 500 OOPS: cannot change directory 錯誤秒解:SELinux 布林值一鍵修復

編輯:Linux 教學

配置完 vsftpd、建立使用者、設定家目錄權限無誤,卻在登入時噴出 500 OOPS: cannot change directory:/home/xaftp?這是經典的 **SELinux 阻擋 FTP 守護程式存取使用者家目錄** 的情境。本文提供最快修復指令並解釋原理。

錯誤現場

C:\>ftp 10.10.1.239
Connected to 10.10.1.239
220 (vsFTPd 2.0.5)
User (10.10.1.239:(none)): xaftp
331 Please specify the password.
Password:
500 OOPS: cannot change directory:/home/xaftp
Login failed.

一鍵修復

setsebool ftpd_disable_trans 1
service vsftpd restart

即可正常登入。

原理深度解析

  • setsebool:設定 SELinux 布林值(開關)。
  • ftpd_disable_trans:將 FTP 守護程式(vsftpd)的**類型轉換** 功能關閉。預設啟用時,vsftpd 進程會從 ftpd_t 轉換為 ftpd_unconfined_t 或其他受限域,導致無法存取標準使用者家目錄標籤 user_home_dir_t。設為 1 後,vsftpd 維持在未受限域,可正常 chdir 至使用者家目錄。

替代方案:調整 SELinux 模式(不建議生產環境)

  1. 暫時放行:setenforce 0(切換至 Permissive 模式,僅記錄不阻擋)
  2. 永久關閉:編輯 /etc/selinux/config,SELINUX=disabled,重開機生效。

最佳實務:保持 SELinux Enforcing,精準調整布林值(ftpd_disable_trans、ftpd_full_access、ftpd_use_cifs 等)或為目錄打正確標籤(chcon -R -t public_content_t /var/ftp),兼顧安全與功能。

排查技巧

查看被阻擋的詳細日誌:

ausearch -m avc -ts recent | audit2allow -w

或直接閱讀 /var/log/audit/audit.log 找 denied 關鍵字,再用 audit2why 分析原因。

Copyright © Windows教程網 All Rights Reserved