Linux Permissions Primer

You may ask yourself when on your own Linux system or come across a blog what linux rw rw r means?  The following primer can help you answer that.  In short, this means User has read/write, Group has read/write and Other has read permissions to whichever file or folder this access is set for.

Ownership

Every file on your Linux system, including directories, is owned by a specific user and group. File permissions are defined separately for users, groups, and others.

User

The username of the person who owns the file. By default, the user who creates the file will become its owner.

Group

The usergroup that owns the file. All users who belong into the group that owns the file will have the same access permissions to the file. This is useful if, for example, you have a project that requires a bunch of different users to be able to access certain files, while others can’t. In that case, you’ll add all the users into the same group, make sure the required files are owned by that group, and set the file’s group permissions accordingly.

Other

A user who isn’t the owner of the file and doesn’t belong in the same group the file does. In other words, if you set a permission for the “other” category, it will affect everyone else by default. For this reason, people often talk about setting the “world” permission bit when they mean setting the permissions for “other.”

Access Permissions

There are three types of access permissions on Linux: read, write, and execute. These permissions are defined separately for the file’s owner, group and all other users.

Read (r)

On a regular file, the read permission bit means the file can be opened and read. On a directory, the read permission means you can list the contents of the directory.

Write (w)

On a regular file, this means you can modify the file, aka write new data to the file. In the case of a directory, the write permission means you can add, remove, and rename files in the directory. This means that if a file has the write permission bit, you are allowed to modify the file’s contents, but you’re allowed to rename or delete the file only if the permissions of the file’s directory allow you to do so.

Execute (x)

In the case of a regular file, this means you can execute the file as a program or a shell script. On a directory, the execute permission (also called the “search bit”) allows you to access files in the directory and enter it, with the cd command, for example. However, note that although the execute bit lets you enter the directory, you’re not allowed to list its contents, unless you also have the read permissions to that directory.

None (-)

No permission is specified by using a hyphen.
Here’s a run down of what the first character could be in any output of ls -l:
d = directory
= regular file
l = symbolic link
s = Unix domain socket
p = named pipe
c = character device file
b = block device file
For permissions, here are the character representations and possibilities:
r = read permission
w = write permission
x = execute permission
= no permission

Example

drw-rw-r-x 2 root root 4096 Oct 31 10:18 test

“test” is a directory with Owner and Group belonging to root.  Permissions for Owner are read and write, and permissions for group are read and write and permissions for Other are execute.

-rw-rw-r-- 2 user1 devs 4096 Oct 10 09:32 linux

“linux” is a file with Owner (user1) having read/write permission, Group (devs) having read/write permission and Other having read permissions.

Published by

Rich

Just another IT guy.

One thought on “Linux Permissions Primer”

Leave a Reply

Your email address will not be published. Required fields are marked *