Linux Permissions, How Do They Work?The Linux permission system for files can appear somewhat confusing to new Linux users. There's a system of letters or numbers all jumbled together in a seemingly unordered mess.
In reality, it's quite simple, once you understand how it's broken down.
Directories, Links, Read, Write, and ExecuteStart off by going to a folder in your
Downloadsfolder is usually a good option. Once you're there, run
$ cd ~/Downloads $ ls -lahYou'll see a listing of all of the files and folders in
DownloadsTo the far left is a column of letters and dashes. That is the notation for permissions.
That glob of letters and dashes can be broken down into four distinct sections. The dashes mean that there isn't a value there or that particular permission isn't enabled.
The first section lets you know if the file is a folder or a symbolic link. This is also the only section that only has one character, the first one. For regular files, that first character is a dash. For folders, it's a
d, and for links, its an
The remaining three sections of three values represent the actual permissions. The first grouping handles the file owner's permissions. The second section is the file's group permissions. The last set of three is the file's public permissions.
It might be somewhat apparent, but each of the permission sections has an
w, and an
xvalue or a dash signifying that that group doesn't have that permission.
rcorresponds to "read,"
wis "write," and
For a better picture of how it works, take a look at this permission listing.
-rwxr-xr--In this case, it's a regular file. The owner can read, write and execute the file. The group can read and write. All other users can only read it.
Take a look at a directory.
drwxr-xr-xBy default, the files in this directory can be read, written, and executed by the owner. The group and anyone else can read and execute.
chmodutility can change the permissions of your files and folders. You need to own the files in order to change them with
chmod, unless you are using it as root or with
ooptions to change the permissions for the owning user, group, and others respectively. Take a look at how it works.
$ chmod g+w somefile.txtThe command above adds write permissions for the group on the file,
chmodcan also remove permissions.
$ chmod o-wx somefile.txtThat command removes write and execute permissions for other users.
You don't have to add or subtract to get the permissions that you want. You can also set the permissions equal to what you need.
$ chmod w=rx somefile.txtThere is also an
aoption to apply a change to all groups simultaneously.
The Numeric SystemIn addition to using letters to represent permissions, Linux also has a numeric system that can simplify the process. The system assigns a value to each permission. Add the numbers together to get the total permission value of the section.
r = 4 w = 2 x = 1So, to set the permissions of a file where the owner has full permissions, the group has read and write, and everyone else only has read, you can use the following command.
$ chmod 764 somefile.txtThe numeric system is often used by applications and web hosting services because it is more concise than the letters. Take a look at this common example:
$ chmod 755 something.phpIn many cases, you'd only want the owner to write the file, but web servers to be able to read and execute it.