One of the benefits of a Linux distro is being able to easily modify file permissions through the terminal. Linux categorizes file owners into 3 groups: User, Group, and Other. By default, the User is the owner of the file and can set permissions to the file through the terminal. A Group can contain multiple users, and it is defined in such a way so that we don't have to set permissions for multiple similar people, and instead can set permissions for a Group for easier control. Other is anyone else who is not the User nor are they in the user-defined Group of users.
Coincidentally, there are also 3 types of Permissions: Read, Write, Execute.
Having the Read permissions allows you to open and view a file.
Having the Write permissions allows you to edit a file and save changes.
Having the Execute permission allows you to run the file if it is an application.
One very important command, the chmod command, allows you to edit file permissions for all 3 of the file owner types that we mentioned earlier. First, we'll go ahead and see what default permissions our files have by making some dummy files and using the command ls -l.
The first character shows what kind of file we are working with, then the following 9 characters specify permissions for the User, Group, and Others in that order. As a quick primer, the characters are labeled as follows:
r: read permission, w: write permission, x: execute permission, -: no permission
Using the chmod command, we can set permissions using the template:
chmod *permissions* *filename*
For example, if we wanted to set file permissions so that the Group has read and write permissions, but they lack execute permissions, we would input the command as:
chmod g=rw test.txt
Similarly, if we wanted to set it so Others have only execute permissions, we could input the command like so:
chmod o=x test.txt
Note that we could also take away or add permissions without affecting any of the other permissions if we use +/- like so:
chmod g+x test.txt
chmod o-x test.txt
This would grant the user Group the execute permission. The second command revokes Other's execute permission.
Comments
0 comments
Please sign in to leave a comment.