When I ssh into my server and login as t 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?

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements None
Est. reading time N/A
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/vivek: No such file or directory

It means when you created a user called vivek, the home directory /home/vivek 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/vivek and set permission, type:
# mkdir /home/vivek
# chown vivek:vivek /home/vivek
# chmod 0700 /home/vivek

Try to login as vivek:
# su - vivek
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 vivek
Sample outputs:

vivek:x:1000:1000:Vivek Gite,,,:/home/vivek:/bin/bash


  1. vivek: 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. Vivek Gite: 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/vivek: Home directory
  7. /bin/bash: The absolute path of a command or shell (/bin/bash)

$ getent group vivek
Sample outputs:


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 3 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • sathish Jun 29, 2012 @ 10:25

    very useful !!!!

  • Afifur Mar 6, 2015 @ 3:50

    Very formative and useful !!

  • Rohit May 5, 2015 @ 8:23

    You should also mention copying “/etc/skel/*” files to “/root” directory. Otherwise you will not get the proper login shell !

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum