Skip to content

Understanding file permissions – Part 2

Beginner's Linux

Hello again! This is Part 2 of my tutorial on understanding file permissions on Linux. If you haven’t already and don’t have much of an understanding of Linux file permissions, try reading Part 1. If you’ve got an understanding, but don’t know how to change them, you could start here!

Changing file permissions – the graphical way

If you’re not too proficient when faced with a black screen and a blinking cursor, all good graphical file manager tools can help you change the permissions. It does help to understand how they work and if you’ve read Part 1, you should know enough to get it.

Here, I’ll focus on Konqueror (KDE’s default) and Nautilus (Gnome’s default) but the same kind of instructions should be relevant to almost any graphical file management tool.

Konqueror

UPDATE: My apologies — the images used in this post cannot be located.

Nautilus

UPDATE: My apologies — the images used in this post cannot be located.

Here it’s the same deal, simply tick as necessary to set permissions. Remember it’s also in the rwxrwxrwx format we explored in Part 1.

There – simple!

Changing permissions – the geeky, I mean, command line way

Of course if you’re willing to dip your toes in the command line, I’ll show you that as well. If you really don’t want to touch the terminal, feel free to stop here. In the command line, the command you use to change permissions is chmod. There are two ways in which you can set the permissions. One of them uses a similar format to rwxrwxrwx that we learnt about earlier, and the other uses numbers. First of all, we’ll look at the symbolic version.

Basically, this involves the use of a letters and symbols.

The first set of symbols consist of u (the user who owns the file) , g (the group), o (other users) and a (all three). These symbols are used for identifying who you want to give permissions. You should have seen these before.

The second set are r (read), w (write) and x (execute). Straightforward hopefully.

Finally, you use + to add permissions, to remove them and = to set them (we’ll talk about the difference later).

So, for example, if I want to give a group of users permission to write to myfile, I first need to check the permissions to see what they are at the moment.

$ ls -l myfile

This will show me the permissions in rwxrwxrwx format on the left hand side.

-rw-r--r-- 1 peter peter 0 Sep 17 12:13 myfile

So, if you remember, this set of permissions means that it’s a file, the owner can read and write, the group can read and everyone else can read. OK, so what do we need to do to make the group have write permissions? We need to add (+) write permissions (w) to the group (g). So if we make that into a symbol sum, it would be g+w (add write to group). So that’s exactly what we do.

$ chmod g+w myfile

Now we check and see if it’s worked:

$ ls -l
-rw-rw-r-- 1 peter peter 0 Sep 17 12:13 myfile

Yes! As you can now see, the group permissions are now rw-, which is read and write. To do it the other way, it’s simply g-w:

$ chmod g-w myfile

So it’s simply a case now of substituting the relevant symbols for what you want to. For instance, if I wanted to give all other users read access, the command would be:

$ chmod o+r myfile

And I can string multiple additions or subtractions or both together like so:

$ chmod g+r+w myfile

Try changing permissions on a few trivial files in your home folder (remember you can always use the graphical tools if you mess something up).

Now there’s also =. We can use this if we want to set multiple permissions at a time and/or we want to overwrite the current settings. Now at the moment there won’t appear to be much difference in doing this and using + and .

Here’s a practical example, in code:

$ ls -l myfile
-rw-r-xr-- 1 peter peter 0 Sep 17 12:13 myfile
$ chmod g=rw myfile
$ ls -l myfile
-rw-rw-r-- 1 peter peter 0 Sep 17 12:13 myfile

Did you notice that the x for group had gone after the chmod command? We didn’t explicitly remove it, but by using =, we removed the old permissions (r-x) and then set the new ones (rw-). If you still don’t get it, look at it the other way as well.

$ ls -l myfile
-rw-r-xr-- 1 peter peter 0 Sep 17 12:13 myfile
$ chmod g+r+w myfile
$ ls -l myfile
-rw-rwxr-- 1 peter peter 0 Sep 17 12:13 myfile

This demonstrates that since we’re adding (+) and not resetting (=), the x stays intact.

Hopefully now you see the difference. + and add or take away permissions, and = resets them all before setting the new ones.

A quick speed tip – you can string commands together if you want to do a lot of work. This time, myfile isn’t readable by anyone at all (the owner still has the ability to change permissions remember). We want to allow read and write access to the owner and read access to the group. We can string the commands together with , (a comma).

$ ls -l myfile
---------- 1 peter peter 0 Sep 17 12:13 myfile
$ chmod u+r+w,g+r myfile
$ ls -l myfile
-rw-r----- 1 peter peter 0 Sep 17 12:13 myfile

Right OK. So if you’re very new to this kind of thing you might want to take a quick break now to get this into your head. Perhaps create some dummy files and practise changing permissions on them. Any questions about my explanation or why something isn’t working? Drop a comment at the end of this post and I’ll help out!

There’s only one more thing I’m going to delve into for this part, and that’s recursive chmodding.

This time I’ve got myfolder, which contains six files. Here they are (this is the result of an ls -l from within myfolder.

total 24
-rwx------ 1 peter peter 0 Sep 18 14:25 file1
-rwx------ 1 peter peter 0 Sep 18 14:25 file2
-rwx------ 1 peter peter 0 Sep 18 14:25 file3
-rwx------ 1 peter peter 0 Sep 18 14:25 file4
-rwx------ 1 peter peter 0 Sep 18 14:25 file5
-rwx------ 1 peter peter 0 Sep 18 14:25 file6

I want to change the permissions of all the files in this folder so that they are rwxrw-r–. Instead of doing each one manually, I can use chmod‘s -R (recursive) feature to apply the permissions to the whole folder. From within myfolder, I run:

$ chmod -R u=rwx,g=rw,o=r .

The -R tells chmod to apply this to the whole folder, then I have my permissions I’m setting, then I have a dot (.). The dot tells chmod to affect this folder – as dot means ‘the current folder’. Lo and behold:

total 24
-rwxrw-r-- 1 peter peter 0 Sep 18 14:25 file1
-rwxrw-r-- 1 peter peter 0 Sep 18 14:25 file2
-rwxrw-r-- 1 peter peter 0 Sep 18 14:25 file3
-rwxrw-r-- 1 peter peter 0 Sep 18 14:25 file4
-rwxrw-r-- 1 peter peter 0 Sep 18 14:25 file5
-rwxrw-r-- 1 peter peter 0 Sep 18 14:25 file6

It worked!

Well, as it turns out, writing this part of the tutorial has taken longer (and ended up longer) than I thought it was going to. So, in Part 3, I’m going to explain the other command line way of chmodding, using the number system.

When Part 3 debuts, this text will contain a link to it. Until then, you can also brush up on Part 1.

When you’re ready, move on to Part 3, or revisit Part 1.

And as with all my tutorials, if you’ve got any suggestions, had a few problems or you genuinely found this useful, I’d love it if you’d drop a comment on this post, it makes writing these so worthwhile!

Like this post?

If you would like to support the time and effort I have put into my tutorials and writing, please consider making a donation.

4 Comments

  1. Chris wrote:

    Fantastic tutorial (as usual!). You should start an all OSS blog!

    Tuesday, September 19, 2006 at 00:53 | Permalink | Using Mozilla Firefox Mozilla Firefox 1.5.0.7 on Windows Windows XP
  2. Peter wrote:

    Thanks!

    Thursday, September 21, 2006 at 10:38 | Permalink | Using Mozilla Firefox Mozilla Firefox 1.5.0.7 on Fedora Linux Fedora Linux
  3. Matthew S. wrote:

    I came across your site from this link here:
    http://fosswire.com/post/2010/07/quick-reference-imagemagick/

    You write awesome tutorials, because your genuine interest shines through to the user reading. (It’s a talent when you can take something like “file permissions on a gnu/linux system” and turn it into a fun and interesting experience!) Thanks.

    Thursday, July 29, 2010 at 15:56 | Permalink | Using Google Chrome Google Chrome 5.0.375.125 on Linux Linux
  4. tonyz wrote:

    Peter, your leaving a legacy.
    I’m truly grateful for sharing your knowledge…

    Saturday, September 11, 2010 at 20:09 | Permalink | Using Internet Explorer Internet Explorer 6.0 on Windows Windows Server 2003

4 Trackbacks/Pingbacks

  1. […] Understanding file permissions – Part 2 […]

  2. FOSSwire » Understanding file permissions - Part 1 on Monday, November 6, 2006 at 20:31

    […] Part 2 is now online and available – read it now! Also Part 3 is available (but read Part 2 first!). […]

  3. […] 2 is now online and available – read it now! Also Part 3 is available (but read Part 2 […]

Post a Comment

On some sites, you must be logged in to post a comment. This is not the case on this site.
Your email address is not made public or shared. Required fields are marked with *.
*
*
*

Posting a comment signifies you accept the privacy policy.
Please note — usually your comment will appear straight away but sometimes it will be held for approval (this is due to the spam filter). If your comment is waiting to be approved, please don’t post it again! It will appear eventually.