
Thursday, 14th February 2008 at 05:42pm
I want to learn about file permissions. Yes, you heard me. I want to learn. I don't actually know much about them yet. Why am I doing an article about them if I don't know what they do, you might ask. And I'd have to reply, "good question. I don't really have an appropriate answer." Onwards?
Unix is a multiuser based operation system, like I mentioned before, so there has to be a way that it controls which files a user can look at. That's done with permissions. At the moment, your /var/www/ is going to be owned by www-user which is a user that Apache made when you installed it. Unless you log in as root, or that user you won't be able to edit or add files in there at the moment. Lets learn how to change that.
First, head to your into your /var/ directory, and then show the files with their data, (if you don't know how to do that, then you should read through a few of the posts I've tagged for commands.)
drwxr-xr-x 4 root www-user 1.0K Feb 12 22:38 www
You'll have something like that for your /www/ directory. The "drwxrwxr-x" is what we're interested in, since that tells us the permissions. The first letter tells us that it's a directory, then the rest are in blocks of three; the first block is for users, then groups, then others.
r means that they can read from that file or directory, the w means they can write to it, and the x is to execute it.
What I did was "chgrp -R shamess /var/www/" and that changed the group so that I was in it (the -R switch was to make all the files and directories inside it change too). Then I needed to give the group permission to edit the files; chmod g+w /var/www.
And that was it. Now you can edit files in your /www/ directory without having to be root.
There's a more detailed article on permission types and how they work over at FreeOS; Understanding Linux file permissions.