Skip to main content
Xsec

Managing Permissions in GNU/Linux

Published on 6 min read

Updated on

Tip

This whole post is write by Olivier Pusadoux from Les hirondelles du net website.

A GNU/Linux operating system has three types of users and three distinct types of permissions. This page presents the most common options for scripts, with a focus on managing website folders and files on an Apache server under GNU/Linux.

For additional information, you can consult ubuntu-fr.org documentation:

The CHmod Command

Types of users:

  • The file owner (user)
  • The owner’s group (group)
  • Other users, or the rest of the world (others)

Types of permissions:

  • r: read permission
  • w: write permission
  • x: execute permission

Binary/Octal Permission Correspondences and Their Meanings

Binary PositionOctal ValuePermissionsMeaning
0000- - -No permissions
0011- -xExecutable
0102- w -Write
0113- w xWrite and execute
1004r - -Read
1015r - xRead and execute
1106r w -Read and write
1117r w xRead, write, and execute

To modify permissions in octal format, the best way to be certain of the result is to add these values.

For example: change the permissions of the “myscript” file so that I (the owner) am the only one who can modify it, people in my group can read and execute it, and everyone else can only execute it:

User TypeOwnerGroupOthers
Permissionsr w xr - x- - x
Binary Position111101001
Octal Value751

Modify permissions on myscript:

Terminal window
sudo chmod 751 myscript

Summary of Different Commonly Used Values

Note

644 - Read, write for owner / Read for others. Default value for a file under GNU/Linux.

User TypeOwnerGroupOthers
Permissionsr w -r - -r - -
Binary Position110100100
Octal Value644
Danger

666 - Read, write for everyone, not recommended

User TypeOwnerGroupOthers
Permissionsr w -r w -r w -
Binary Position110110110
Octal Value666
Note

700 - Read, write, execute only for owner Default value for a directory under GNU/Linux

User TypeOwnerGroupOthers
Permissionsr w x- - -- - -
Binary Position111000000
Octal Value700
Note

705 - Owner has all permissions / Group none / Others read and execute Recommended by some providers for the site directory if it’s inaccessible (message: “Forbidden…”)

User TypeOwnerGroupOthers
Permissionsr w x- - -r - x
Binary Position111000101
Octal Value705
Note

755 - Owner has all permissions / Others read and execute Useful for scripts for example and certain website files

User TypeOwnerGroupOthers
Permissionsr w xr - xr - x
Binary Position111101101
Octal Value755
Note

764 - All permissions for owner / Read, write for group / Read only for others Sometimes useful for website files belonging to www-data group

User TypeOwnerGroupOthers
Permissionsr w xr w -r - -
Binary Position111110100
Octal Value764
Note

774 - All permissions for owner and group / Read only for others Useful for certain files on a local development server

User TypeOwnerGroupOthers
Permissionsr w xr w xr - -
Binary Position111111100
Octal Value774
Note

775 - All permissions for owner and group / Read and execute for others Very practical for simplifying website management in development on a local server (in the media folder)

User TypeOwnerGroupOthers
Permissionsr w xr w xr - x
Binary Position111111101
Octal Value775
Danger

777 - All permissions for everyone Strongly discouraged! But may be necessary for CMS cache locally (for example) on a LAMP server

User TypeOwnerGroupOthers
Permissionsr w xr w xr w x
Binary Position111111111
Octal Value777

To modify permissions of a directory and its subdirectories, use the recursive function -R Modify the directory /var/www/html/mysite with permissions changed to 755:

Terminal window
sudo chmod -R 755 /var/www/html/mysite

Display Directory Permissions

The permissions of files in a directory can be displayed using the “ls -l” command

Display permissions of files in the /var/www/html/mysite directory:

Terminal window
ls -l /var/www/html/mysite

Permission Format

The permission format is a list of 10 symbols.

The 1st symbol is either ”-” or “l” or “d”, indicating whether it’s:

  • a file (-)
  • a link (l)
  • or a directory (d)

Then follow the three groups of three permission symbols (rwx-). For example: -rw-r--r-- means it’s a file with permissions set to 644 drwx------ means it’s a directory with permissions set to 700 lrwxrwxrwx means it’s a link with permissions set to 777

The Advantage of CHown

To avoid chmod 666 (or worse, 777), CHown allows you to change the file owner.

If you want to reclaim ownership rights on an entire folder and you are the user “martin”:

Terminal window
sudo chown -R martin /path/to/folder

Recover permissions on the entire folder:

Terminal window
sudo chmod -R 755 /path/to/folder
Use with an AI

Actions