How To Change Owner Of Home Directory In Linux With Extra Tip
In this article, you will learn how to change ownership of the directory in the correct way. Changin directory required in many cases but here we have covered where every Linux admin and user stuck in daily task. These cases are enough to understand the changing ownership of the directory.
Environment
- RHEL 6
- RHEL 7
- RHEL 8
- All Linux flavors
Issue
- Change Owner of Home Directory
Command
chown -R user:group directoryname
Setup an environment:
We will add two test users abc and xyz for our environment to understand how to change ownership of home directory.
[root@explinux home]# useradd abc
[root@explinux home]# passwd abc
Changing password for user abc.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@explinux home]# ls
abc
[root@explinux home]# ll
total 0
drwx------ 2 abc abc 83 Apr 11 07:28 abc
[root@explinux home]# useradd xyz
[root@explinux home]# passwd xyz
Changing password for user xyz.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@explinux home]# ls
abc xyz
[root@explinux home]# ll
total 0
drwx------ 2 abc abc 83 Apr 11 07:28 abc
drwx------ 2 xyz xyz 62 Apr 11 07:29 xyz
[root@explinux home]#
Case 1:
Change Complete Ownership of Directory
ISSUE:
# userdel abc
# useradd abc
In this case, the user will create with new UID and GID, no Home directory will create for new user because the same name home directory already presented in the home directory. You will get warning also at the time of local user creation. In the case of AD and LDAP, you will not get any prior error messages.
Resolution
Case 2:
Change User Ownership of Directory
# chown -R xyz abc
Case 3:
Change Group Ownership of Directory
# chown -R :xyz abc
Extra Tip:
Change home directory of the user
# chown -R xyz:xyz abc
# usermod -d /home/xyz abc
Now at this point, you become perfect in changing ownership of the directory without any error. Share this article to show your care.