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:
For example, here I have created a home directory for the linuxhint user, so I named the directory as /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:
For example; for my linuxhint user, I have run the below given command:
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:
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:
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.
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:
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.