Privacy and personal space are two important things when it comes to interaction between humans. The level of these two parameters varies among person to person. We all have person(s) in our life to whom we share our private matters with, a group to which we hangout and others, to whom we would like to keep a distance and show some positive attitude. This is one among things which makes us feel human. Like this, it is important that we set some sort of curtailment to our files in the computer system. That is where I would like to introduce the CHMOD command comes into play.
In simple words, CHMOD is a command used on Linus or Unix based systems to set file and directory access permissions. Why CHMOD? With the help of CHMOD command we can define which users can access the file and how can they access it. Let me show you how CHMOD works using a simple example.
How CHMOD works
To start, this is how the command syntax will look like;
chmod options permissions file name
We start by writing the ‘chmod’ and then options, you can specify list of users and their permissions under options, permissions are read, write and execute. Finally, the name of the file.
The type of people to whom we are going to assign permissions are generally classified into three; user (u), group (g) and others (o). Permissions can be specified by using letters read (r), write (w) and execute (x). You can also use octal numbers (0 to 7), this will be explained later.
Here is another example;
Let’s say my file name is helloworld. I want the following permissions to be set for the users;
- I can read, write and execute the file. I mean, the user (u) can read (r), write (w) and execute (x).
- Members of the group (g) can only read (r) and execute (x)
- Finally, for others (o) only read (r) permission is allotted.
My command will look like;
chmod u=rwx,g=rx,o=r helloworld
In the above command; chmod is used to specify we are going to change mode. u, g, o represents user, group and others respectively. w, r, x represents write, read, execute permissions.
Instead of writing the letters, octal representation of permissions is the widely-used command. To begin with;
- The octal value for read is 4
- Write is 2
- Execute is 1
- and, for no permission the octal value is 0
So, if you say 7 it means read, write and execute. How? Well, 7 is a combination of (4+2+1). You can create lot of combinations using 4,2,1 and 0. Some example combinations are;
Remember, if you say;
chmod 754 helloworld
The digits 7,5 and 4 represents permission for the user, group and others respectively. 7 is 4+2+1 means (read, write and execute) permission for the user. 5 is 4+0+1 means (read, no write and execute) permission for the group members and 4 is 4+0+0 means (read, no write, no execute) for others.
Extra chmod command options
Apart from the standard options read, write and execute, there are lot many command options which can be used along with chmod.
- Verbose – outputs a diagnostic for every file processed
- Changes – outputs a file whenever there is a change
- Silent – to ignore the error messages
- And more;
If you are like me, definitely you would have searched for chmod generator online. Well, the folks at chmodcommand.com has made an amazing calculator which will generate the chmod command as per your selection of options. I find this really interesting and easy to use.
Chmod is a great command which always comes in handy especially, when you are dealing with sensitive information. It will only take a few minutes to get used to all the commands and then in no time you will be an expert in the same.