折騰vsftp。。。

500 OOPS: cannot change directory:/home/*******”處理方式[其實本質就是目錄要有執行權限纔可以進入]

1、vsftpd本地用戶不能登錄問題的解決:
打開/etc/selinux/config

將selinux=enforcing或permissive改成disabled。

重啓vsftp服務!

2、 用戶是否被 vsftpd 限制登錄, 比如用戶名在 /etc/ftpusers 中,並被阻止登錄了。

3、 vsftpd.conf 中是否打開了pam認證的選項 (自己編譯安裝的時候常因爲這個出錯) (看vsftpd.conf中是否有pam_service_name=ftp或vsftpd.到底是哪個要看。
PAM模塊的服務文件/etc/pam.d下是誰.我的是ftp且它的配置如下:

#%PAM-1.0
auth required /lib/security/pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeed
auth required /lib/security/pam_unix.so shadow nullok
auth required /lib/security/pam_shells.so
account required /lib/security/pam_unix.so
session required /lib/security/pam_unix.so
如果/etc/ftpusers有的用戶將被deny

4、 相關文件夾和文件是否有權限:

關於“vsftpd 部分本地用戶不能登錄,部分可以”的問題,
系統中原來就有的本地帳號都不能登錄,我的/etc/vsftpd/vsftpd.conf文件的配置如下:

local_enable=YES
write_enable=YES
chroot_local_user=YES
pam_service_name=vsftpd
/etc/pam.d/vsftpd存在且正常。

登錄時錯誤信息都是一樣的:
500 OOPS: cannot change directory:/home/xxxx
Login failed.
421 Service not available, remote server has closed connection

他們的home目錄都是/home/xxxx。/home和/home/xxxx的權限都是755。
以上這些帳號都不能ftp登錄,這些都是平常經常使用的,可以用shell登錄的。

我新創建了一個xxx帳號
# useradd xxx –G lzh -d /tmp/xxx
能ftp登錄,他的home爲/tmp/xxx,在/分區上。而/home我是mount到/dev/hda9上的。
#mount
/dev/hdb1 on / type ext3 (rw)
/dev/hda9 on /home type ext2 (rw)

所以,我猜想:是否是由於/home分區的原因,而造成“主目錄在/home分區的帳號”都不能登錄呢?

爲了驗證以上設想,我試着再創建了一個帳號
useradd –m lzh
/home, /home/lzh 的權限都是755。

lzh ftp登錄失敗。
500 OOPS: cannot change directory:/home/usr3
Login failed.
421 Service not available, remote server has closed connection

至此,我覺得可以確定是由於/home分區的原因,而造成“主目錄在/home分區的帳號”都不能登錄。

參考文章:
I finished my second upgrade to Fedora Core 4. Not everything is ironed out yet with the build of course. But one thing is for sure a lot has happened to the RedHat I knew before.

I must say of all the changes, for me the nicest addition is the new SELinux extensions. For deep background on the reasons for and theory of SELinux read, The Inevitability of Failure: The Flawed Assumption of Security in Modern Computing Environments

The more I work with SELinux the more I realize I need to know about it, and how exactly it does all its stuff. It certainly changes things relating to users, directories and access. As I am starting to learn it, I’m sure I’m doing things the hard-way.

The major difference, so far for me, in Red Hat’s SELinux is the way ftp is handled. vsftpd is still the server which is great. However, it seems to be designed to run as a daemon rather than invoked via xinet.d. If you grab a working copy of the xinet.d file for vsftpd you can invoke it via xinet.d wrapper. I did my first server upgrade in this manner. The current one I am trying as a daemon. I certainly think I will miss some of the features that the xinet.d wrapper brings, and may yet return to it.

Of all the issues I saw most notable is if you want to enable chroot directory’s outside of the normal /home/xxx vsftpd. These will fail with a

500 OOPS: cannot change directory: /mnt/xxxxx

I was able to use ftp if I logged in with an account with a directory in /home, but once I set a user account to have a home drive outside of /home (in this case on a mounted secondary disk) vsftpd barfs the above.

I found information at the NSA that indicates you can disable SELinux protection of the ftp daemon.

setsebool -P ftpd_disable_trans 1

This seems a bit drastic. It certainly works for now though.

I think ultimately the issue resides with policies, but as SELinux policies are new to me, it will take time before it all gets sorted out. As I spend time with the new SELinux extensions in Fedora Core 4 I will keep you updated on my thoughts and configuration lessons.

解決辦法:
# setsebool ftpd_disable_trans 1

# service vsftpd restart

在ssh輸入命令:
setsebool ftpd_disable_trans 1
爲避免每次開機都要作這個操作,可在setsebool命令後面加上-P選項,使改動永久有效。
service vsftpd restart

解決方法如下,需要將capability模塊加載,
手動加載模塊:
# modprobe capability
或者編譯進內核:
CONFIG_SECURITY_CAPABILITIES: This enables the “default” Linux capabilities functionality.
If you are unsure how to answer this question, answer Y.
Symbol: SECURITY_CAPABILITIES [=y]
Prompt: Default Linux Capabilities
Defined at security/Kconfig:56
Depends on: SECURITY
Location:
-> Security options
-> Enable different security models (SECURITY [=y]

關於vsftp碰到的問題對摺騰*nix service的總結[其實就是*nix的保護機制]:

1、如果開了selinux,首先排除這個。

2、配置不允許(基本就是*nix提供的那一堆配置文件),unix編程藝術提到最高境界就是玩這些配置文件。

3、文件系統的保護機制(文件系統對目錄和文件的讀寫執行權限的控制)

發佈了23 篇原創文章 · 獲贊 6 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章