Introduction to basic Linux permissions

by

Linux permissions are often very confusing to new users coming from Windows to Linux for the first time. Casual Linux users that have been using it for years may even misunderstand this topic and so I thought it would handy to write a small guide that would hopefully be very easy to understand.

Types of permissions

There are 3 basic permissions:

TypeFileDirectory
ReadRead the contentList the contents of the directory
WriteWrite or modify into the fileDelete directory, create new files inside it
ExecuteRun script or binary fileEnter directory
File permissions

To read a file, we can use the cat command. To write into the file, we can use a text editor such as vim or nano. To enter a directory, we can cd into it, and to list the contents of a directory we can use the ls command.

Users, groups, and other

Permissions in Linux has three "tiers", the first is the User permission, which applies to the owner of a file. The second is the Group permission which applies to the group that owns the file and the third is the Other permission which applies to everyone else. How do we assign these? Hold on tight as I explain that next.

How do I use this?

The command we use in unix-based operating systems to change user permissions is the chmod command. the syntax is like this:

chmod  

But what do we put under?

Well there's two methods, the first is to use an octal value. Fear not, it's actually very simple.

Basic octal permission values

  • 4 - Read
  • 2 - Write
  • 1 - Execute
  • 0 - No permissions (Deny all)

So if you wanted to grant a read permission on a file called test you'd do it like this:

chmod 400 test

The first number is a User permission, which means grant a read to the owner of the file, second is the group permission which we deny everything, and the third is the other permission which we also deny all.

But what if we wanted to grant a read and a write on a file? If we own this file then we probably want to do both. Well it's really simple, you simply take the Read value (4) and the write value (2) and you add them together (4+2) to get the value 6. so now the command looks like this:

chmod 600 test

Easy right?
But what if we wanted to modify a permission instead of setting all three together?

Using non octal values

The alternative to octal values, and the solution to the previous problem is to use letters instead of numbers. The three octal values are represented like so:

  • r
  • w
  • x

And for User Group and Other we'll use:

  • u
  • g
  • o

So to solve our previous problem, and add an additional permission to a file or directory with existing permissions we'll use something like this:

chmod u+x test # Meaning, to add the execute permission to the owner of a file.

You can also set the three permissions together like so:

chmod ugo=rwx test  # giving the read write execute permissions for everyone.

I hope this has been educational for you and I'll see you next time!