Linux file permissions explained (2024)

Posted: January 10, 2023 | | by Scott McBrien (Red Hat)

Image

Linux file permissions explained (1)

File permissions are core to the security model used by Linux systems. They determine who can access files and directories on a system and how. This article provides an overview of Linux file permissions, how they work, and how to change them.

How do you view Linux file permissions?

The ls command along with its -l (for long listing) option will show you metadata about your Linux files, including the permissions set on the file.

$ ls -ldrwxr-xr-x. 4 root root 68 Jun 13 20:25 tuned-rw-r--r--. 1 root root 4017 Feb 24 2022 vimrc

In this example, you see two different listings. The first field of the ls -l output is a group of metadata that includes the permissions on each file. Here are the components of the vimrc listing:

  • File type: -
  • Permission settings: rw-r--r--
  • Extended attributes: dot (.)
  • User owner: root
  • Group owner: root

The fields "File type" and "Extended attributes" are outside the scope of this article, but in the featured output above, the vimrc file is a normal file, which is file type - (that is, no special type).

The tuned listing is for a d, or directory, type file. There are other file types as well, but these two are the most common. Available attributes are dependent on the filesystem format that the files are stored on. For Red Hat Enterprise Linux 7, 8, and 9, the default filesystem format is XFS.

How do you read file permissions?

This article is about the permission settings on a file. The interesting permissions from the vimrc listing are:

rw-r--r–

This string is actually an expression of three different sets of permissions:

  • rw-
  • r--
  • r--

The first set of permissions applies to the owner of the file. The second set of permissions applies to the user group that owns the file. The third set of permissions is generally referred to as "others." All Linux files belong to an owner and a group.

When permissions and users are represented by letters, that is called symbolic mode. For users, u stands for user owner, g for group owner, and o for others. For permissions, r stands for read, w for write, and x for execute.

[ Learn how to manage your Linux environment for success. ]

When the system is looking at a file's permissions to determine what information to provide you when you interact with a file, it runs through a series of checks:

  1. It first checks to see whether you are the user that owns the file. If so, then you are granted the user owner's permissions, and no further checks will be completed.
  2. If you are not the user that owns the file, next your group membershipis validated to see whether you belong to the group that matches the group owner of the file. If so, then you're covered under the group owner field of permissions, and no further checks will be made.
  3. "Others" permissions are applied when the account interacting with the file is neither the user ownernor in the group that owns the files. Or, to put it another way, the three fields are mutually exclusive: You can not be covered under more than one of the fields of permission settings on a file.

Permissions go beyond the different types of people that can interact with a file. Each user gets an expression that includes the three basic types of permissions. In the example above, the owner of the file is given the following permissions:

rw-

Each character in the expression indicates whether a specific permission is granted or not. In the example above, read (r) permission and write (w) permission have been granted on the file. However, the execute permission (x) is not granted, which is why there's a - sign in the expression. The permission in this field is disabled.

Consider the group owner's permissions in this example:

r--

The read (r) permission is granted to members of the group, but write and execute have both been disabled.

[ Keep your most commonly used commands handy with the Linux commands cheat sheet. ]

What are octal values?

When Linux file permissions are represented by numbers, it's called numeric mode. In numeric mode, a three-digit value represents specific file permissions (for example, 744.) These are called octal values. The first digit is for owner permissions, the second digit is for group permissions, and the third is for other users. Each permission has a numeric value assigned to it:

  • r (read): 4
  • w (write): 2
  • x (execute): 1

In the permission value 744, the first digit corresponds to the user, the second digit to the group, and the third digit to others. By adding up the value of each user classification, you can find the file permissions.

For example, a file might have read, write, and execute permissions for its owner, and only read permission for all other users. That looks like this:

  • Owner: rwx = 4+2+1 = 7
  • Group: r-- = 4+0+0 = 4
  • Others: r-- = 4+0+0 = 4

The results produce the three-digit value 744.

Skip to bottom of list

What do Linux file permissions actually do?

I've talked about how to view file permissions, who they apply to, and how to read what permissions are enabled or disabled. But what do these permissions actually do in practice?

Read (r)

Read permission is used to access the file's contents. You can use a tool like cat or less on the file to display the file contents. You could also use a text editor like Vi or view on the file to display the contents of the file. Read permission is required to make copies of a file, because you need to access the file's contents to make a duplicate of it.

Write (w)

Write permission allows you to modify or change the contents of a file. Write permission also allows you to use the redirect or append operators in the shell (> or >>) to change the contents of a file. Without write permission, changes to the file's contents are not permitted.

Execute (x)

Execute permission allows you to execute the contents of a file. Typically, executables would be things like commands or compiled binary applications. However, execute permission also allows someone to run Bash shell scripts, Python programs, and a variety of interpreted languages.

[ Download now: A sysadmin's guide to Bash scripting. ]

There are other ways to execute the contents of a file without execute permission. For example, you could use an interpreter that has execute permission to read a file with instructions for the interpreter to execute. An example would be invoking a Bash shell script:

$ bash script.sh

The executable being run is bash. The script.sh file is read by the Bash interpreter, and its commands are executed. The content in this article is general purpose, but in Linux, there are often additional ways to accomplish tasks.

Skip to the bottom of list

Image

Download now

How do directory permissions work?

Directory file types are indicated with d. Conceptually, permissions operate the same way, but directories interpret these operations differently.

Read (r)

Like regular files, this permission allows you to read the contents of the directory. However, that means that you can view the contents (or files) stored within the directory. This permission is required to have things like the ls command work.

Write (w)

As with regular files, this allows someone to modify the contents of the directory. When you are changing the contents of the directory, you are either adding files to the directory or removing files from the directory. As such, you must have write permission on a directory to move (mv) or remove (rm) files from it. You also need write permission to create new files (using touch or a file-redirect operator) or copy (cp) files into the directory.

Execute (x)

This permission is very different on directories compared to files. Essentially, you can think of it as providing access to the directory. Having execute permission on a directory authorizes you to look at extended information on files in the directory (using ls -l, for instance) but also allows you to change your working directory (using cd) or pass through this directory on your way to a subdirectory underneath.

Lacking execute permission on a directory can limit the other permissions in interesting ways. For example, how can you add a new file to a directory (by leveraging the write permission) if you can't access the directory's metadata to store the information for a new, additional file? You cannot. It is for this reason that directory-type files generally offer execute permission to one or more of the user owner, group owner, or others.

[ Want to test your sysadmin skills? Take a skills assessment today. ]

How do you modify Linux file permissions?

You can modify file and directory permissions with the chmod command, which stands for "change mode." To change file permissions in numeric mode, you enter chmod and the octal value you desire, such as 744, alongside the file name. To change file permissions in symbolic mode, you enter a user class and the permissions you want to grant them next to the file name. For example:

$ chmod ug+rwx example.txt$ chmod o+r example2.txt

This grants read, write, and execute for the user and group, and only read for others. In symbolic mode, chmod u represents permissions for the user owner, chmod g represents other users in the file's group, chmod o represents other users not in the file's group. For all users, use chmod a.

Maybe you want to change the user owner itself. You can do that with the chown command. Similarly, the chgrp command can be used to change the group ownership of a file.

Skip to bottom of list

What are special file permissions?

Special permissions are available for files and directories and provide additional privileges over the standard permission sets that have been covered.

  • SUID is the special permission for the user access level and always executes as the user who owns the file, no matter who is passing the command.
  • SGID allows a file to be executed as the group owner of the file;a file created in the directory has its group ownership set to the directory owner. This is helpful for directories used collaboratively among different members of a group because all members can access and execute new files.

The "sticky bit" is a directory-level special permission that restricts file deletion, meaning only the file owner can remove a file within the directory.

Want to take a deeper dive into special permissions? Read Linux permissions: SUID, SGID, and sticky bit.

Wrapping up

Understanding Linux file permissions (how to find them, read them, and change them) is an important part of maintaining and securing your systems. You can learn more about file permissions for Red Hat Enterprise Linuxby checking out thedocumentation or by practicing with a self-paced lab on using file permissions.

[ Cheat sheet: Get a list of Linux utilities and commands for managing servers and networks. ]

Topics: Linux administration Security

Linux file permissions explained (2024)

FAQs

What are the basics Linux file permissions? ›

What do Linux file permissions actually do?
  • Read (r) Read permission is used to access the file's contents. ...
  • Write (w) Write permission allows you to modify or change the contents of a file. ...
  • Execute (x) Execute permission allows you to execute the contents of a file. ...
  • Read (r) ...
  • Write (w) ...
  • Execute (x)
Jan 10, 2023

What is the meaning of chmod 777? ›

The command chmod -R 777 / makes every single file on the system under / (root) have rwxrwxrwx permissions. This is equivalent to allowing ALL users read/write/execute permissions. If other directories such as home, media, etc are under root then those will be affected as well.

What are 3 different types of permissions in Linux explain in detail? ›

They specify who can do what with a file or directories on a system and how. Linux file permissions are based on three distinct types of permissions: read, write, and execute. In other words, these Linux permissions are a set of attributes that determine who can access a file or directory, and what they can do with it.

Why we use chmod 400 in Linux? ›

Gives the user read permission, and removes all other permission. It means to protect a file against the accidental overwriting, removing, renaming or moving files.

What does chmod 755 mean? ›

755 means you can do anything with the file or directory, and other users can read and execute it but not alter it.

What are the three standard Linux permissions? ›

read – The Read permission refers to a user's capability to read the contents of the file. write – The Write permissions refer to a user's capability to write or modify a file or directory. execute – The Execute permission affects a user's capability to execute a file or view the contents of a directory.

Why is 777 permission not a great idea? ›

Similarly, permission 666 gives read and write permission to every user. However, access mode 777 goes beyond this by allowing execution as well. Such open permissions could enable tinkering with sensitive files. Therefore, using lax permissions is generally not a good idea.

What is the difference between 777 and 755? ›

Some directory permission examples:

777 - all can read/write/search. 755 - owner can read/write/search, others and group can only search.

What is chmod 666 or 777? ›

A text file has 666 permissions, which grants read and write permission to everyone. A directory and an executable file have 777 permissions, which grants read, write, and execute permission to everyone. Typically, users override the system defaults in their /etc/profile file, .

How do you control access to files in Linux? ›

To change file permissions in Linux, you can use the ` chmod` command followed by the desired permission settings. For example: If we want to grants read, write, and execute permissions to the owner, and read and execute permissions to the group and others.

How to check the permission of a file in Linux? ›

To view the permissions of a file or directory in Linux, you can use the "ls -l" command to display the symbolic notation of permissions or the "stat -c" command to obtain the numeric representation.

Who owns the file in Linux? ›

User: A user is the one who created the file. By default, whosoever, creates the file becomes the owner of the file. A user can create, delete, or modify the file.

Why use chown? ›

Bhagwad Park. The chown command in Linux is used to assign ownership. Every file and directory can have only one user and one group as an owner. In Linux, the concept of ownership is key to understanding file access, security, resource management, and accountability.

Does chown need sudo? ›

To execute the chown command, a user will have to be registered on the list of sudoers, and temporarily gain elevated privileges through the use of the sudo command.

What is the difference between chmod 400 and 777? ›

Other combinations are also common: 666 (110 110 110) is read/write for everyone but not execute), while 555 (101 101 101) is read/execute for everyone but not write, and 400 (100 000 000) is read-only for the owner and no access for anyone else. And that's why 777 means all permissions.

What are the default Linux file permissions? ›

On Linux, by default, when we create new files, they are given rw-rw-r– permissions (depending on the umask). The r, w, and x signify the read, write, and execute permissions, respectively.

Which three 3 permissions can be set on a file in Linux? ›

The three basic file permissions in Linux are read, write, and execute.

What does chmod 644 do? ›

644 - owner can read/write, group/others can read only.

What is chmod 700? ›

To remove all permissions for group and world you would type chmod 700 [filename]. To give the owner all permissions and world execute you would type chmod 701 [filename]. To give the owner all permissions and world read and execute you would type chmod 705 [filename].

Top Articles
Walmart Supercenter, York, PA - Reviews, Ratings, Tips and Why You Should Go – Wanderlog
Search Results - Obituaries published on Winnipeg Free Press Passages
Monitor por computador e pc
Tripadvisor London Forum
Atrium Attorney Portal
Temu Beanies
Enneagram Test Eclecticenergies Spotify
911 Active Calls Caddo
Craigslist Worcester Massachusetts: Your Guide to the City's Premier Marketplace - First Republic Craigslist
Is Holly Warlick Married To Susan Patton
Ihop Logopedia
Dangerous Cartoons Act - Backlash
Top Football Recruits 2017
1v1 lol unblocked Game- Play Unblocked Game Online for Free!
Ethiopia’s PM pledges victory in video from front line
Xsammybearxox
Model Center Jasmin
Real Caca Girl Leak
Watch The Lovely Bones Online Free 123Movies
Bj지밍
Panic! At The Disco - Spotify Top Songs
Pcc Skilled Nursing Login
Handshoe's Flea Market & Salvage Llc Photos
Sterling Primary Care Franklin
Burlington Spectrum Tucson
My Les Paul Forum
How to get tink dissipator coil? - Dish De
Https //Paperlesspay.talx.com/Gpi
Tackytwinzzbkup
Edict Of Force Poe
Wjar Channel 10 Providence
Bing Chilling Copypasta - Ricky Spears
Natalya's Vengeance Set Dungeon
Need flooring installation? Carpet Hardwood floor Vinyl plank Laminate - skilled trade services - craigslist
The Little Mermaid 2023 Showtimes Near Marcus South Pointe Cinema
Mychart University Of Iowa Hospital
Calverton-Galway Local Park Photos
Tamusso
Traftarım 24
Matt Laubhan Salary
Yakini Q Sj Photos
Left Periprosthetic Femur Fracture Icd 10
Atlanta Farm And Garden By Owner
Melissa Bley Ken Griffin
Online-Shopping bei Temu: Solltest du lieber die Finger davon lassen?
Google Halloween Game 2018 Unblocked
13364 Nw 42Nd Street
Senna Build Guides :: League of Legends Strategy Builds, Runes, Items, and Abilities :: Patch 14.18
Auctionzipauctions
Cb2 South Coast Plaza
What stores are open on Labor Day 2024? A full list of where to shop
Latest Posts
Article information

Author: Zonia Mosciski DO

Last Updated:

Views: 5726

Rating: 4 / 5 (51 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Zonia Mosciski DO

Birthday: 1996-05-16

Address: Suite 228 919 Deana Ford, Lake Meridithberg, NE 60017-4257

Phone: +2613987384138

Job: Chief Retail Officer

Hobby: Tai chi, Dowsing, Poi, Letterboxing, Watching movies, Video gaming, Singing

Introduction: My name is Zonia Mosciski DO, I am a enchanting, joyous, lovely, successful, hilarious, tender, outstanding person who loves writing and wants to share my knowledge and understanding with you.