File ownership is fundamental in Linux. As every file is associated with an owner and a group, we can change the owner of a file or directory using the chown command.
Using chown to change ownership of files and directories
How to do it...
To understand the use of chown, let's follow these steps:
- To understand the use of the chown command, let's create a file named file1.txt and a user named user1:
The previous command for changing password information is optional. You can ignore it if you want to.
- Now, let's check the current owner of file1.txt.
We can see that the current owner for both the files is root and it belongs to the root group.
- Let's change the ownership of file1.txt to user1:
As seen...