Change File Ownership and Permissions
To change the owners of a file, you can use the following commands:
chown
This changes the user who owns a particular file or directory.
chgrp
This changes the group who owns a particular file or directory.
To change the permissions that the owners of a file have, you use the chmod
command.
chmod
takes two arguments: the permissions to give a file, and the file to change the permissions of. The permissions are represented as a 3-digit number, where each digit represents the permissions to give the user, group, or others, respectively.
Read, write, and execute permissions are represented by the following numbers:
r - 4
w - 2
x - 1
If you want to give someone multiple permissions, you add the numeric representations of those permissions together. For example:
Read, write, execute (rwx) permissions = (4 + 2 + 1) = 7
Write, execute (_wx) permissions = (2 + 1) = 3
So let's say you want to give a file the following permissions:
The user that owns the file should be able to read, write, and execute the file. rwx = (4 + 2 + 1) = 7
The group that owns the file should be able to read and execute the file. r_x = (4 + 1) = 5
Anyone else should have no permissions for the file. ___ = 0
The you'd run the following command:
Remembering the syntax for this command can be quite cumbersome, so I recommend using a third-party website such as https://quickref.me/chmod.
Last updated