Basic Linux Directory Permissions and How to Check them

Linux permissions directory are a fundamental aspect of system security and management. They determine which users and processes can

  • Read

  • Write

  • Execute files and directories. 


Thereby ensuring proper access control. 

Understanding Linux Directory Permissions

In Linux, each file and directory is associated with several permissions. They determine what actions can be performed on them. These permissions are divided into:


Owner: The user who owns the file or directory.

Group: A set of users who share certain permissions.

Others: All other users on the system.


Permissions for these categories are represented by a combination of

 Read (r): Permission to read the contents of the file or directory.

Write (w): Permission to change the contents of the file or directory.

Execute (x): Permission to execute the file as a program or to access the directory's contents.

Permission Representation

Permissions are displayed using the `ls -l` command. It lists files and directories and their permissions in a specific format. For example:


drwxr-xr--


This string can be broken down as:

The first character indicates the file type (`d` for the directory, `-` for a regular file, `l` for symbolic link, etc.).

The next nine characters represent the permissions, grouped in threes:

  The first set of three (after the type character) is for the owner.

  The second set is for the group.

  The third set is for others.


In the example above:

 `d` indicates it's a directory.

`rwx` means the owner has read, write, and execute permissions.

`r-x` implies the group has read and executed permissions but not written.

 `r--` means others have only read permission.

Changing Permissions

Permissions can be modified using the `chmod` command. It  stands for "change mode." There are two ways to use `chmod`: 

Symbolic Method

The symbolic method uses letters to represent permissions:

 `u` for user (owner)

 `g` for group

 `o` for others

-` a` for all (user, group, and others)


And the following symbols to set or remove permissions:

`+` to add a permission

`-` to remove a permission

`=` to set a specific permission


For instance, to add execute permission for the group on a directory:


chmod g+x directoryname

Numeric Method

The numeric method uses octal numbers to represent permissions. Each type of permission is assigned a number:


 Read (`r`) is 4

Write (`w`) is 2

Execute (`x`) is 1


These numbers are summed to get a numeric representation of the permissions. For example:

- `rwx` (read, write, execute) is 4 + 2 + 1 = 7

- `r-x` (read, execute) is 4 + 0 + 1 = 5

- `r--` (read only) is 4 + 0 + 0 = 4


To set permissions using the numeric method, use `chmod` followed by a three-digit number representing owner, group, and others. For example:



chmod 755 directory name


This command sets the permissions to `rwxr-xr-x.` Thus, the owner has full access and read/execute access to the group and others.


 Checking Directory Permissions

The `ls -ld` command is useful for checking directory permissions. For example:


ls -ld /path/to/directory


This command displays detailed information about the specified directory, including its permissions.

Additionally, the `stat` command provides comprehensive details:


stat /path/to/directory


This outputs information, including permissions in symbolic and numeric formats, ownership, and timestamps.


 Practical Examples

Suppose you have a directory `/home/user/docs` and you want to check its permissions:


ls -ld /home/user/docs


Output might be:


drwxr-xr--


This indicates that its a directory in which 

The owner has full permissions

The group can read and execute

Others can only read.


To change its permissions so that everyone can read and write but not execute:


chmod 666 /home/user/docs


This sets the permissions to `rw-rw-rw-`.

To Sum It Up!

Linux permission directory is a crucial security component that should be well understood to manage systems efficiently. The `ls,` chmod, and stat commands enable users to control and check permissions.

Was this answer helpful? #2 #4
 

Did We Miss Out on Something?

Relax, we have you covered. At Go4hosting, we go the extra mile to keep our customers satisfied. We are always looking out for opportunities to offer our customers “extra” with every service. Contact our technical helpdesk and we’d be more than happy to assist you with your Cloud hosting, Colocation Server, VPS hosting, dedicated Server or reseller hosting setup. Get in touch with us and we’d cover all your hosting needs, however bizarre they might be.

Submit your Query

  • I'm not a robot

Browse by ServicesBrowse by Services

Resource Library

What is Cloud Computing

Understand the term cloud computing, the ongoing trend, its playing field, future growth and how industry...

Myths about Cloud Computing

Cloud computing, in the recent years, has become a subject of significant discussion among the industry experts.

Download Now

Did We Miss Out on Something?

Relax, we have you covered. At Go4hosting, we go the extra mile to keep our customers satisfied. We are always looking out for opportunities to offer our customers “extra” with every service. Contact our technical helpdesk and we’d be more than happy to assist you with your Cloud hosting, Colocation Server, VPS hosting, dedicated Server or reseller hosting setup. Get in touch with us and we’d cover all your hosting needs, however bizarre they might be.

Submit Query

Please fill in the form below and we will contact you within 24 hours.