3

Let me clarify my question.

I have a CentOS 6 virtual machine, with /home directory mounted on a logical volume (formed by 2 virtual HDDs). I used this command to create a new user named user03

useradd user03 -c "User 03"

and give him a password:

passwd user03

Everything happened normally. But when I log in with user03, CentOS give me this notification:

No directory /home/user03!

Logging in with home = "/"

The weird thing is: /home/user03/ does exists and associated with user03 and user03 has full access. When I do this

[user03@vm0 /]$ cd

[user03@vm0 ~]$ pwd

/home/user03

working directory changes back to /home/user03/ as it's supposed to do.

So is there anything wrong with my system? Why does it tell me that "No directory /home/..." while that directory does exists?

  • What is output of ls -ld /home? – cuonglm Jan 15 '15 at 8:53
  • @cuonglm It said: drwxr-xr-x. 6 root root 4096 Jan 15 14:05 /home – Tuan LE Jan 15 '15 at 9:12
  • How about ls -ld /home/user03? – cuonglm Jan 15 '15 at 9:14
  • For that, it said: > drwx------. 2 user03 user03 4096 Jan 15 14:51 /home/user03 – Tuan LE Jan 15 '15 at 9:15
  • 2
    The permission seems to be fine. Maybe it's selinux issue. Try restorecon -r /home then try login again. – cuonglm Jan 15 '15 at 10:00
1

This comment was right, it's an SELinux problem. Running this command and then logging in again fixes the problem:

restorecon -r /home
0

The useradd command will create home directory if CREATE_HOME yes was set in /etc/login.defs file.

From useradd manual:

       Create the user's home directory if it does not exist. The files and directories contained in the skeleton directory (which can be defined
       with the -k option) will be copied to the home directory.
       useradd will create the home directory unless CREATE_HOME in /etc/login.defs is set to no.

But since you said /home/user03 exists and belongs to user03 and proper permissions are set to it, The problem may cause from your /etc/passwd file Otherwise do the following:

mkdir /home/user03
chown user03:user03 /home/user03
cp /etc/skel/* /home/user03
chmod 700 /home/user03

The 6th field is the user home address, maybe your /etc/passwd file is disturbed or useradd didn't add this field to this file (I don't know what happened!). However you can edit this file and add the user home address to it.

My userid in /etc/passwd file is this:

Sepahrad:x:500:500:Sepahrad:/home/Sepahrad:/bin/bash
  • Thanks @sepahrad-salour ! I checked the /etc/passwd and here's the result: user03:x:502:502:Utilisateur 03:/home/user03:/bin/bash So that means passwd does add this field, right? – Tuan LE Jan 15 '15 at 9:23
  • x in 2th filed means your password is hashed and stored in /etc/shadow/ file, Please read my post again. – Sepahrad Salour Jan 15 '15 at 9:37
  • Cool, your useradd command translated the comment field for you :-) Are the home directories mounted via autofs perhaps? – wurtel Jan 15 '15 at 9:47
  • @SepahradSalour: thanks. I did as what you posted but it's the same. It seems there's nothing wrong with /etc/passwd or permissions of /home/user03/. CREATE_HOME yes is in /etc/login.defs so that why /home/user03/ is created. I'm really confused where this error comes from. – Tuan LE Jan 15 '15 at 10:26
  • @wurtel: oh it's not smart like that :D, it's because I modified the comment field with usermod. /home/ is manually mounted via fstab file. – Tuan LE Jan 15 '15 at 10:29
-1

My solution has been to change the permission of home directory.

chmod 777 /home

I know, give all permissions for all users is not the best solution but at the moment it works fine.

  • 2
    this is very bad idea – Jakuje Jun 16 '16 at 17:39
  • 755 would be better and is what /home is usually set to, owned by root:root. – garethTheRed Jun 16 '16 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.