Professional Documents
Culture Documents
Create New User Poblem
Create New User Poblem
in Linux
November 11, 2022 by cyberithub
In this article, we will see how to solve "Could not chdir to home directory
/home/xxxx: No such file or directory" error if you are also getting this. In Linux,
every user is linked to its home directory so whenever you login to your Server, it will
search the user's home directory under /home location. If Server does not able to find
the home directory then it will throw "Could not chdir to home directory
/home/xxxx: No such file or directory" error.
But it does not mean you won't be able to login to your System. You will still be able to
login but it will change your login location to / path. This can be easily checked by
running pwd command immediately after you login.
It is ok if you get the error in some Lab or test server where you can easily delete the
user account and create it again with home directory assigned but the problem usually
occurs when you have lots of files and directories created using that user account and
by the time you realized now you cannot delete the user and recreate it again.
Sometimes this becomes a very complicated situation. We will see how to deal with this
problem with the help of an example in below section.
NOTE:
Please note that in my case I am using Ubuntu 20.04 LTS Server. You might be
using some different Linux distribution. It might not be same for you.
testuser@192.168.0.108's password:
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
applicable law.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
applicable law.
There are two different ways to fix "Could not chdir to home directory
/home/testuser: No such file or directory" error depending on which server you
are working on and how critical is the user's account. You can choose either of the
below method as per your requirements.
If you are getting the error in some lab or test server where you can easily delete and
recreate the user then the quickest way to solve this error is to delete the user by
using userdel testuser command as shown below.
cyberithub@ubuntu:~$ sudo userdel testuser
And then recreate the user with sudo useradd testuser -m command as shown
below. This will solve your problem in no time. Check more about useradd command.
Now when you login to the server with this user, you won't get "Could not chdir to
home directory /home/xxxx" error again. This can be confirmed by
using pwd command immediately after login as shown below.
testuser@192.168.0.108's password:
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
applicable law.
$ pwd
/home/testuser
Second scenario could be that you cannot delete the created user now but you still have
to get rid of this error. In those cases, it is always advised to create user home directory
manually and then link that directory to user account. So Let's create the user's home
directory first by using mkdir /home/testuser command.
Then provide a login shell using --shell switch and link home directory using --
home switch.
Finally transfer all the user's file from source location to user's home directory using
below cp command.
testuser@192.168.0.108's password:
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
testuser@ubuntu:~$ pwd
/home/testuser
testuser@ubuntu:~$
Hope above solution would be enough to solve your "Could not chdir to home
directory /home/xxxx: No such file or directory". Please let me know your
feedback in the comment box !!