Monday, July 29, 2013

Moving User's Home Directory and Its Common Errors

Hello everybody,
Today, I would like to talk about a very common error in users' home directories. Have you ever seen these errors?

Could not update ICEauthority file (Figure 1):

                                                                          Figure 1

or "There is a problem with the configuration server. (/usr/libexec/gconf-sanity-check-2 exited with status 256)" (Figure 2)

                                                                            Figure 2

or "Nautilus could not create the following required folders" (Figure 3)

                                                                               Figure 3

They are very common errors in Linux world when you move user's home directory and some users/admins, especially new users/admin in Linux, simply can't fixed it and they reinstall Linux again. However, it has a very simple solution and some users are not aware of this simple solution.


Let's start with an example:
First, login as a root and create a user:

useradd test-user

create some dummy files there by switching to this user (Figure 4):

su - test-user
touch abc ab ac abcd
pwd
exit


                                                                                Figure 4

Take a look inside the test-user's home directory (Figure 5):

ls -al /home/test-user

                                                                                 Figure 5

Now, let's move user's home directory to new location (Figure 6):

mkdir -p /new-home
tar czf - /home/test-user | (cd /new-home ; tar -xvzf -)


the above command will compress user's home directory and decompress it into new location. "-" force tar command to send its output to stdout then receive its input from stdin. 

                                                                                 Figure 6

Use ls command to make sure your files are there:

ls -al /new-home/home/test-user

Complete ownership of all files and directories (Figure 7):

chown -R test-user.test-user /new-home/home/test-user

                                                                              Figure 7

Now, let's delete test-user's old directory (Figure 8):

rm -rf /home/test-user

Now, login with test-user (Figure 8):

su - test-user

And yes, you would see the error that I was talking about:

                                                                                  
                                                                              Figure 8

 and if you try to login with GUI, you would see those errors as I showed you above.

The problem is that you moved user's home directory but you didn't update /etc/passwd file and that's why the su command complained or you saw those odd errors in GUI. You can fix it easily with usermod command. Just type the following command (Figure 9):

usermod -d /new-home/home/test-user test-user

                                                                                 Figure 9

You should be fine now.Try to login again:

su - test-user

and here you go (Figure 9). To see your present work directory, type pwd.
And that's all.
Hope you enjoyed.
Khosro Taraghi