Raspberry Pi

How to Change Default User Home Directory in Raspberry Pi

The Raspberry Pi system has a default user “pi” and all the data stored on the system are available in the default directory, which is “/home/pi”. However, if multiple users are working on the system, you may need at some point to change the default home directory in order to secure your personal data.
If you are searching for a way to change the default user home directory on the Raspberry Pi system, you should follow this article’s guidelines.

Change the Default User Home Directory in Raspberry Pi

First, let me share with you, how a “pi” home directory looks like. By default, the pi directory has some sub-directories which are common in each Raspberry Pi system, those sub-directories include Downloads, Music, Pictures, Templates, and others. Not just directories other content can also be present here as shown in the image below:

It is not easy to manually move all the content to another user’s home directory, and for that propose follow the below-written steps to change the default user home directory in Raspberry Pi:

Step 1: Creating a New Home Directory

The first step is to create a new home directory, this directory is for any previously created user or a new user. To create a directory, run the below-written command:

sudo mkdir -pv /home/<username>

For example, here I have created a home directory for the linuxhint user, so I named the directory as /home/linuxhint:

sudo mkdir -pv /home/linuxhint

Step 2: Changing Owner of Pi

To move all the content of pi (default user) to the newly created home directory, it is mandatory that the new directory has access to pi directory’s content and for that, use the below-mentioned chown command:

sudo chown pi /home/<username>

For example; for my linuxhint user, I have run the below given command:

sudo chown pi /home/linuxhint

Step 3: Moving Content from “pi” to New Home Directory

After changing the owner, it is time to move the content from the pi directory to the newly created directory by using the below-written “mv” command:

sudo mv /home/pi/* /home/linuxhint

Step 4: Changing usermod

After moving all the content now finally run the below-mentioned command to change the usermod, so that new directory can be assigned as home directory:

sudo usermod -d /home/linuxhint -m pi

Although it is not mandatory, it is recommended to reboot the system after moving the content and changing the user mode. So that the system could restart with all the content moved to the new home directory.

reboot

Step 5: Verify

Finally, just to verify that everything is done as expected, go to the created directory, mine was linuxhint so I opened it and you can see that all the content has moved here successfully:

If you want to verify by using the command line then you can use the below-mentioned ls command:

ls -l /home/linuxhint

Note: To alter the changes back to an original directory, repeat these steps from the start and instead of linuxhint, use “pi”.

Conclusion

To change the default user home directory in Raspberry Pi, firstly create a new home directory then change the owner of pi. After that move the content from the default (pi) directory to the newly created directory. Finally, change the “usermod” to assign new directory as the home directory and verify by opening the new home directory.

About the author

Zahra Zamir

An Electronics graduate who loves to learn and share the knowledge, my passion for my field has helped me grasp complex electronics concepts and now I am here to share them with others.