Using chown to change ownership of files and directories
Controlling access to files and directories really just boils down to ensuring that the proper users own files and directories, and that each file and directory has permissions set in such a way that only authorized users can access them. The chown
utility covers the first part of this equation.
One unique thing about chown
is that you must have sudo privileges to use it, even if you're working with your own files in your own directory. You can use it to change the user of a file or directory, the group that's associated with a file or directory, or both at the same time.Â
First, let's say that you own the perm_demo.txt
file and you want to change both the user and group association to that of another user. In this case, I'll change the file ownership from me to Maggie:
[donnie@localhost ~]$ ls -l perm_demo.txt -rw-rw-r--. 1 donnie donnie 0 Nov 5 20:02 perm_demo.txt [donnie@localhost ~]$ sudo chown maggie:maggie perm_demo.txt [donnie...