Understanding Linux File Permissions

Understanding Linux File Permissions

Understanding Linux File Permissions

Linux File Permissions are one of the things that make Linux Secure, and in that case Insecure, depending on how they are set. I have seen many horrible tutorials, etc that attempt to explain permissions. The hope for this blog is that it is actually able to help someone understand Permissions. Let’s get Started.

First thing we need to know is that there is types of permissions that exist in Linux

  • 1) Owner
  • 2) Group
  • 3) Everyone Else In the World (anyone that’s not the owner or in the group)

as you can see there is coincidentally three sets of three permissions that can be set on a file

The First 3 are for the Owner, the Second 3 are for the Group, and the 3rd is for Everyone, sound familiar?

Let’s talk about the Numbers, what do they mean?

  • 7 – Read/Write/Execute
  • 6 – Read + Write Access
  • 5 – Read + Execute
  • 4 – Read
  • 3 – Write + Execute
  • 2 – Write
  • 1 – Execute
  • 0 – No Permissions

so to tie the numbers to letters Read, Write, and eXecute

So there is a number associated with the permissions for each permission type (this is as technical as it gets, if you are lost, see below it will all make sense in a second)

To View Permissions, usually you issue a ls -l, the L outputs in List form top-to bottom

So what does drwxrwx— mean?

d= Directory (or folder)

the rwx following is for Read, Write, and Execute as mentioned before

so this Folder above has read/write/Execute Permissions for Owner and Group (7), but Nothing for Everyone (0), making that permission 770. This is generally a good permission to set.

Let’s do another example, ls -l

so this file named test.txt is owned by root, and a group of BackupAdmins

In this case, we have root with Read/Write and Execute (7)  and no permissions for the Group (0) and Read Permission to Everyone Else who can browse to that directory.

One more for Good Measure before moving on

so in this case we have a file that has No Owner Permission (0), Read/Write/Execute Permission to Everyone in the BackupAdmins Group (7), and Read/Execute Permissions for Everyone Else.

How To Change Linux Permissions?

let’s say we have the file, with the above permissions of 770, and we want to make it so that Owner/Group have full access, however everyone else can read, issue the following command:

chmod 774, and then the Filename/Folder

How Do I Change Owner Of a File in Linux?

you use the basic syntax of chown the username that you want to be owner, and then the name of the File/Folder you are changing ownership of

How Do I change the Group of a File In Linux?

Same concept as Change Owner, basically chgrp, the Groupname you would like to change to, and the Name of the File/Folder that you are changing

Test:

What’s Wrong with this?

— Answer Below —

The answer to this is more of a question of common sense. The Permissions are 777

In 99% of scenarios, the highest permission you should EVER need is 775. If you are managing Groups properly, you should never have to use 777, not to mention that it’s not secure at all to have anyone/everyone be able to read/write/execute, this is how “remote code execution” happens, by having too much permission.

Congratulations, you are a Zwiegnet certified Linux Permissions Master!

Hosted Linux Servers at www.zwiegnet.com/go

Leave a Reply

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