SL6: Non-standard home directories, Error: `Could not chdir to home directory` upon login, but `cd $HOME` works

rhel6scientific-linux

I have a brand new Scientific Linux 6 instance (Similar to RHEL6 & CentOS6), running on Parallels.

The home directory is in a non-standard location, which I'll call /homedir

When I ssh into this box I get an error:

laptop $ ssh 192.168.1.100
stefanl@192.168.1.100's password: 
Could not chdir to home directory /homedir/stefanl: Permission denied

But then immediately afterwards I can chdir to that directory, without an error:

[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

In addition, as root I can su to my account and it seems to work fine. If I didn't have permission to chdir to this directory, I would expect to see an error.

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

Why do I get an error during the initial login, but then I can cd to that same directory immediately afterwards?

Best Answer

It could be an SELinux issue. Check /var/log/audit/audit.log for any related messages. See this informative post for more information, including a possible fix:

# chcon -t home_root_t /homedir/stefanl