How to set folders permissions in linux?

by buster.gaylord , in category: General Help , 7 months ago

How to set folders permissions in linux?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by georgiana.senger , 7 months ago


To set folder permissions in Linux, you can use the chmod command. Here's a guide on how to do it:

  1. Open the Terminal.
  2. Identify the folder for which you want to set permissions. For example, if the folder's path is /path/to/folder, enter the following command: cd /path/to/
  3. To check the current permissions of the folder, use the ls -l command: ls -l You will see an output similar to this: drwxr-xr-x 2 user group 4096 Mar 1 10:52 folder The permissions are represented by the first ten characters. The d indicates that it is a directory. The next three characters (rwx) represent the owner's permissions, the next three (r-x) are the group's permissions, and the last three (r-x) indicate permissions for others.
  4. Now, let's say you want to modify the permissions to allow write access for the owner, read-only for the group and others. You would use the chmod command and set the permissions using numbers. The number 4 represents read, 2 represents write, and 1 represents execute permissions. Add these numbers together to set multiple permissions. In this case, you would want to set 6 for the owner (4 for read + 2 for write), 4 for the group (4 for read), and 4 for others (4 for read). Use the following command to apply the permissions: chmod 644 folder The chmod command modifies permissions, 6 sets permissions for the owner, 4 sets permissions for the group, and 4 sets permissions for others. folder is the name of the folder for which you want to set permissions.
  5. Verify the folder's permissions by using the ls -l command again: ls -l You should see the updated permissions displayed: drw-r--r-- 2 user group 4096 Mar 1 10:52 folder The rw- indicates that the owner has read and write permissions, the r-- shows read-only permissions for the group and others.

Congratulations! You have successfully set the folder permissions in Linux using the chmod command.


by enrico , 2 months ago


Please note that the chmod command offers a variety of options beyond using numbers for permissions. You can also set permissions using symbolic notation for more flexibility. For example:

To give read and write permissions to the owner, but only read permissions to the group and others, you can use the symbolic notation like this: chmod u=rw,g=r,o=r folder

This command sets read and write permissions for the owner (u), read-only permissions for the group (g), and read-only permissions for others (o) on the folder.

Using symbolic notation may be more intuitive for some users, allowing you to explicitly specify the permissions for the user (owner), group, and others. The symbolic notation consists of three parts:

  • The target (u for user/owner, g for group, and o for others).
  • The operator (= for setting permissions, + for adding permissions, - for removing permissions).
  • The permissions (r for read, w for write, x for execute).

You can explore the different ways to set permissions using the chmod command based on your needs and preferences.