Eyh!!! I own that!

usersNow that we know how to change object’s permissions, let’s take a look at how to change object’s ownerships. Like we have already learned, objects can have two types of ownerships: user ownership, and group ownership. We shall learn how to change both individually, and at the same time. Looks boring? Keep reading so I can change your opinion! (or not…)

The basic command to change ownership is chown. You use it, giving a general syntax example, by typing chown -option_flags user:group object. Between the user and group, you can use either a . or : (user:group or user.group, both are acceptable).

There are a few option flags you can use, read the man page for chown to learn them. I think the most important one is the -R (Recursively change ownership of directories and their contents), but this, I leave you to decide.

Chown accepts different methods for setting permissions, and you can see that they are easy to remember:

  • owner - it only changes the object’s owner
  • owner: - changes the owner, and, automatically changes the group to the login or primary group of the user
  • owner:group - it changes both the group and the owner at the same time
  • :group - it only changes the group, leaving alone the user ownership

Now let’s go through a few examples…
Imagine you are user spider and you have the primary group users. When you create a file, default permissions are set (-rw-r- -r- -) and the file gets spider ownership and group users ownership. If you want to give that file to someone outside the users group, it will be able to read it, but not modified it, because the world trio bit (the others) is only readable.
Let’s say that the user you give the file to is ladybug, and her primary group is ladybug. You could use chown ladybug object1 and this will leave the file object1, with the ownership of ladybug.
Let’s say, both spider and ladybug belong to dbugs group. You could chmod 660 objec1 (user and group = read and write), and then chown spider:dbugs object1, leaving the file with user ownership unchanged but the group ownership set to dbugs. Since spider and ladybug have secondary group dbugs, they both can read and change the contents for object1. Getting the big picture by now?

The chown command, like I said can be used both in files and directories, and you can use it to change full directories and its contents. Just use the -R option, on a directory as target, and both the directory and everything inside it, will get the ownership you set. Example: chown -R spider:dbugs /pictures, will change directory pictures and everything inside to user spider and group dbugs.

That’s it! Practice a little, so you get the hang of it. Like everything in Linux, you will find it a lot easier with time and practice, to do things around the command line. Master these easy steps and you are in your way to proficiency! Have phun!



   Share This

0 comments ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment

Creative Commons License
dbugs.org by Marco Garcês is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License.