Linux File Permissions Tutorial

By | February 10, 2011

Linux file permissions is a crucial and most basic concept you have to learn if you are new linux. Most beginners find it really confusing but I don’t think its really that confusing anyway. Whole lot of security for the linux machines is based on the file permissions. So, be careful to learn file permissions before you muck with any of the root files.


I will make this tutorial as simple and as short as I can to save both your time and mine. So, linux files have 3 kind of permissions,

1: Read – r
2: Write – w
3: Execute -x
4: Setuid – s (Rarely found in the execute field)
5: ‘-‘ indicates that no permission is set.

You can find the file permissions of the files by using this command.

ls -l

Use this to get better outout.

ls -l | awk ‘{print $1″<===>”$8}’

Note that “<===>” in the above command is just a separator. This command would display just the file permissions of the file or directory.

The file permissions has 10 characters. You can find it as follows,

d r w e r w e r w e

The first character can possibly indicate one of the following fields.

* d = directory
* l = symbolic link
* s = socket
* p = named pipe
* – = regular file
* c= character (unbuffered) device file special
* b=block (buffered) device file special

2-4 charecters species the file permissions set for the corresponding to the user logged in.

5-7 shows the permissions for the group the file belongs to. The permissions in the group remains all same for all the members in the group.

8-10 talks about permissions for others. Setting permissions for others will allow any other user use the files based on the permissions set.

Here is how to set permissions as a root.

chmod u+rwx filename
chmod g+rwx filename1
chmod o+rwx filename2
chmod a+rwx filename3

The above commands are used to set the read, write and executable permissions to user, group, others and all respectively. You can also control type of users with the permissions like this.

Read this:

u – user
g – group
o – others
a – all
r – read
w – write
x -executable

chmod ug+rw filename4

The above command will only set user and group permissions to read and write only. You can set your permissions based on your need.

Setting Sticky Directory:

If you notice the file permissions of the /tmp you should see something like this.

drwxrwxrwt 13 root root …

t‘ represents that this directory can be used gobally to read, write and delete files by any user.

Setting Group ID:

Setting setguid will tell the system that all the users in group are owners to the files in a directory. Here is how you can set it.

chmod g+s dirname

You can also set group permissions with numbers.

chmod 777 filename

The above command works similar to chmod ugo+rwx filename.

This is something similar to the following.(Following is just a demonstration for your understanding)

r w x – r w x – r w x
1 1 1 – 1 1 1 – 1 1 1
7 – 7 – 7

Now the first 7 represents the user, second one for the group and the third one for others. Find the
following snap to find more.

That’s all i’ve got for now. I hope this explains basic concepts of file permission. Let me know if you have any questions or any corrects that I have to make.

If you like this article, then please consider sharing it. Sharing really inspires us to do things much better!!

One thought on “Linux File Permissions Tutorial

  1. Pingback: Linux File Permissions Examples | Linux Tutorials

Leave a Reply

Your email address will not be published. Required fields are marked *