I build on the knowledge from the last linux quickie and take it a bit further to show you more interesting things about ownership and permissions.
On the last linux quickie we touched the subject of File ownership for users and groups. We’re going to take a deeper look at how the permissions looks in linux and how to change it. So let’s start!
We start with a simple command to get the permissions set for the log files in
$ ls -ld /var/log and get a similar output to this:
Now let’s dissect the result we get into a couple of sections:
First of we have the permissions set for this file/ directory. In this case it’s a directory since we used the
-d flag. I’m talking about the
drwxr-xr-x “gibberish”. So what does it say? It’s actually quite easy. You just have to dissect it into the right sections:
The first d indicates us that it’s a directory.
The rest of the sections represent the permissions for owning user, owning group and everyone else. In this order. So the first section
rwx means the owner of the file has read, write and execute rights on the directory. The owning group and everyone (
r-x for both) have only read and execute permissions.
For directories, the execute permissions allows the users to use cd to change into the directory. The read permissions allows commands like ls. Write permissions should be obvious: To create, rename or delete files.
The number right after the permissions stands for the numer of symbolic (soft) links or directories inside this directory.
After the numbers you see two times
root. That’s just a bit of an unlucky coincidence here. Beacuse they’re actually two different roots. The first root is the object owner. The user called root (which is really bad practice for security reasons). The second root is the user group called root. You should know about users and groups by now. If not, catch up here.
The rest of the “data” is actually not relevant for file ownership but interesting as it is. You can read more about it here.
Changing Ownership and Permissions
To change ownership of a file use the command chown. You’ll need root permissions to run this command. The usage is quite simple, too:
- user ownership:
$ chown username /path/to/file
- group ownership:
$ chown :groupname /path/to/file
- user and group ownership:
$ chown username:groupname /path/to/file
(combo wombo, where you at!?!?!?)
Of course the command comes with flags and additional features. Read more about them in one of the links given at the end of the article.
The same things that chown does for ownership, the command chmod does for permissions. Remember that “gibberish” at the beginning of the post (drwx… etc). You can change the values with this command. And there are a lot of different ways to do it. If you’re familiar with octal system you might want to use the octal method. Since this topic is so big in itself, and can take up quite a lot of time to explain, you can read more about it here.