How to Add and Remove File Permissions on Linux

How to Add and Remove File Permissions on Linux Using the chmod Perintah Command

In the previous Learn Terminal tutorial section, we learned how to set permissions using the command chmod. In this tutorial, we use numbers or the format numeric to indicate the access rights to be granted.

Other than how to use numbers or formats numeric To denote the access rights granted, there is actually another way that we can use, namely by using the direct letter “r”, “w”, “x” format, and the letters “u”, “g” and “o” to denote the recipient of the right. access.

For those of you who may have difficulty using the numeric format, you can use this letter format. This method is also more flexible because it can be used to easily add or remove only one access right to a file, for example, only adding or removing access rights. execute on the user, or otherwise.

How to Set Access Rights Using Font Format

Just like in the previous part of the tutorial, we will use the command chmod to set access rights to a file, only this time using direct letter notation. The access rights to be granted are defined directly in the notation “r” for the access rights read“w” for access rights write and “x” for access rights execute.

Objects that receive access rights are also defined directly in letter notation, the letter “u” represents user“g” represents groupand “o” represents other which means every other user who is not user owner and user in group the owner of the file.

The access rights granted are written directly after the object receiving the access rights by using a hyphen “=” and each object is separated by using a “,” (comma) without the need for a space after it.

For example you want to give access rights read and write for user and groupwhereas other will only get access rights read against the script.js file in the Home directory, then you can do this by using a command like the following:

chmod u=rw,g=rw,o=r script.js

Then the desired access rights will be given to the object as desired, to check whether the access rights have been granted as desired, then you can do this by using the command ls –then you will see the permissions as desired as in the image below:

Setting Access Rights Using Font Format
Setting Access Rights Using Font Format

How to Add Special Access Rights to a File

By using this font format, we can also add and remove only one special access right to an object receiving access rights without disturbing other permissions that already exist.

For example you want to add access rights execute only to user in the previous script.js file, you can do this by using a command like the following:

chmod u+x script.js

You can use the command ls -l to check whether user have managed to get the access rights granted, then user will get access rights execute as previously desired as in the image below:

Adding Access Rights Only To Users
Adding Access Rights Only To Users

If you want to add access rights to more than one object receiving permissions, for example you want to grant access rights execute to user and also groups, you can write them by separating each object using a comma as follows:

chmod u+x,g+x script.js

Or in another case, if you want to add one permission for all objects (users, groups, and other) at once, for example you you want to grant access rights execute To all, you can do this by using a command like the following:

chmod +x script.js

Then all objects (users, groups, and other) will have access rights execute as desired as in the following image:

Adding Access Rights To All
Adding Access Rights To All

How to Remove Special Access Rights to a File

As mentioned above, in addition to adding special access rights to an object, you can also remove special access rights that an object already has. For example group have rights read access, write and execute against the “script.js” file as in the image above before.

Then you want to remove access rights write and execute for group against the file, you can do this by using the “-” sign as in the following command:

chmod g-wx script.js

Then access rights write and execute for group against the “script.js” file will be deleted, to prove it you can use the command ls -l to see the permissions for a file as shown below:

Removing Access Rights Only From User Group
Removing Access Rights Only From User Group

Same as before, if you want to remove the permissions of more than one object (not just on group like the example above), you can do this by separating each object by using a comma as in the example of how to add access rights before.

Enough of this tutorial Learning Terminal on how to add and remove permissions for a file on Linux. In the next section we will learn how to change the file ownership and group permissions of a file

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *