轉載:http://www.ppkj.net/tag/selinux/
開了SELinux和防火牆,沒想到引出了vsftp的問題。FTP登入報錯:500 OOPS: cannot change directory。下面來看看產生這個問題的原因和對策。
首先,分析一下衝突原因:
1. 為鎖定使用者在自己的home目錄中,在vsftpd.conf開啟chroot_local_user。
這樣FTP登入使用者的“/”,就是passwd中的home path,比如/var/www/a.com/。避免FTP使用者跑到/etc亂闖。這樣設定過,FTP登入時,會自動執行CWD /var/www/html/www.xxx.com,並且把這個目錄設定為FTP進程的根目錄,使用者就無法離開了。 vi /etc/vsftpd/vsftpd.conf# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
chroot_local_user=YES
# chroot_list_enable=YES
# (default follows)
# chroot_list_file=/etc/vsftpd/chroot_list
# 當然也可以用chroot_list_enable=YES的辦法。但要逐個在chroot_list中指定FTP使用者名稱,很麻煩。也容易出現疏漏。所以還是推薦用chroot_local_user來限制。
2. 下面,問題就出來了。開啟SELinux後,SELinux會阻止ftp daemon讀取使用者home目錄。所以FTP會甩出一句 “500 OOPS: cannot change directory”。無法進入目錄,出錯退出。
解決辦法有兩個:
1. 降低SELinux安全層級,把enforcing降低到permissive vi /etc/sysconfig/selinux# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - SELinux is fully disabled.
SELINUX=permissive
這時FTP的登入功能就正常了。但降低整體系統安全作為代價來解決一個小問題,這總不是最佳方案。
2. 經過研究,又找到了另一個更理想的辦法。首先查看SELinux中有關FTP的設定狀態: getsebool -a|grep ftpallow_ftpd_anon_write --> off
allow_ftpd_full_access --> off
allow_ftpd_use_cifs --> off
allow_ftpd_use_nfs --> off
allow_tftp_anon_write --> off
ftp_home_dir --> off
ftpd_connect_db --> off
ftpd_disable_trans --> on
ftpd_is_daemon --> on
httpd_enable_ftp_server --> off
tftpd_disable_trans --> off
經過嘗試發現,開啟ftp_home_dir或者 ftpd_disable_trans。都可以達到在enforcing層級下,允許FTP正常登入的效果。 setsebool -P ftpd_disable_trans 1
或者
setsebool -P ftp_home_dir 1 setsebool -P allow_ftpd_full_access 1 service vsftpd restart
加-P是儲存選項,每次重啟時不必重新執行這個命令了。最後別忘了在/etc/sysconfig/selinux中,修改SELINUX=enforcing。