Could not chdir to home directory /root: No such file or directory Error and Solution

When I ssh into my server and login as the root user and I’m getting the following error on screen:

Could not chdir to home directory /root: No such file or directory

How do I fix this error under CentOS or Debian Linux server?

The error message is clear. /root home directory does not exists or deleted by you. If you see the following error:

Could not chdir to home directory /home/demo: No such file or directory

It means when you created a user called demo, the home directory /home/demo was not created. To fix this problem create missing directory and apply current permission. To create a directory called /root and set permission, type:
# mkdir /root
# chown root:root /root
# chmod 0700 /root

To create a directory called /home/demo and set permission, type:
# mkdir /home/demo
# chown demo:demo /home/demo
# chmod 0700 /home/demo

Try to login as demo:
# su - demo
Please note that you may need to adjust directory owner, group, and permissions as per your setup.

Finding more information about the user account

To fetch user account entries from administrative database (/etc/passwd and /etc/group), enter:
$ getent passwd demo

Sample outputs:

demo:x:1000:1000:Demo User,,,:/home/demo:/bin/bash

Where,

  1. demo: Login name / username
  2. x : Password: An x character indicates that encrypted password is stored in /etc/shadow file.
  3. 1000: User ID (UID)
  4. 1000: The primary group ID (stored in /etc/group file)
  5. Demo User: The comment field. It allow you to add extra information about the users such as user’s full name, phone number etc. This field use by finger command.
  6. /home/demo: Home directory
  7. /bin/bash: The absolute path of a command or shell (/bin/bash)

$ getent group demo

Sample outputs:

demo:x:1000:
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s