SL6:非标准的主目录,错误:`login时不能chdir到主目录`,但`cd $ HOME`有效?

我有一个全新的Scientific Linux 6实例(类似于RHEL6和CentOS6),运行在Parallels上。

主目录位于非标准位置,我将称其为/ homedir

当我进入这个盒子时,我得到一个错误:

laptop $ ssh 192.168.1.100 [email protected]'s password: Could not chdir to home directory /homedir/stefanl: Permission denied 

但之后立即可以chdir到该目录,没有错误:

 [stefanl@localhost /]$ cd /homedir/stefanl [stefanl@localhost ~]$ touch foo [stefanl@localhost ~]$ ls -la total 28 drwx------. 3 stefanl wheel 4096 Sep 14 17:53 . drwxr-xr-x. 5 root root 4096 Sep 14 17:16 .. -rw-------. 1 stefanl stefanl 303 Sep 14 18:16 .bash_history -rw-r--r--. 1 stefanl stefanl 18 May 26 08:46 .bash_logout -rw-r--r--. 1 stefanl stefanl 176 May 26 08:46 .bash_profile -rw-r--r--. 1 stefanl stefanl 124 May 26 08:46 .bashrc -rw-rw-r--. 1 stefanl stefanl 0 Sep 14 17:46 foo 

另外,作为根我可以su我的帐户,它似乎工作正常。 如果我没有权限chdir到这个目录,我希望看到一个错误。

 [stefanl@localhost ~]$ pwd /data/homedir/stefanl [stefanl@localhost ~]$ touch bar [stefanl@localhost ~]$ 

为什么在初始login过程中出现错误,但之后我可以立即切换到同一个目录?

这可能是一个SELinux问题。 检查/var/log/audit/audit.log以获取任何相关消息。 看到这个内容丰富的post了解更多信息,包括一个可能的修复:

 # chcon -t home_root_t /homedir/stefanl 

没有将SELinux设置为允许的正确命令是: #chcon -t home_root_t /homedir (注意缺less的stefanl目录)