Changing Directory and File Permissions in Linux
Changing directory and file permissions on a computer is very important task for every system administrator. Using permissions, you can determine which users to have access to a certain file or directory, and what their access allows them to do. The things they can do are read, write, and execute.
Read permission means that if you have this permission, you can open the file or directory.
Write permission means you have editing capabilities. You can make and save changes to the file or directory.
Execute means that if the file is a program, it can be executed.
Before you change permissions, let’s first see what permissions are already set to a file or directory. Let’s begin by looking at the permissions of the files and subdirectories in a current directory. From the terminal, use the following command:
ls -l
The ls command lists the contents of directories. If no path is given, it lists the files in the current directory. The -l option lets you display a variety of information ( including permissions, owner, size, modification time, etc.) about the files contained in the selected directory. For example if you want to see a detailed information about the files in your Home directory just type the following in the terminal:
ls -l /home
To understand how to read permissions, just look at the picture above. If you look at the left column of the figure, you will see the following: drwxr-xr-x or something. Analyzing this information is simple; the “d” stands for directory. If this first character is replaced by a – (dash), then it is a file. A “l” means that it is a link to something else in the file system. Next to the “d“, you will see characters that you need to divide into three groups of three ( in our case the first group is rwx , the second is r-x and the third is also r-x ). The first group contains rwx, which means read, write, and execute. This first group of permissions belongs to the owner of the file or directory. The second group is r–x. This group describes the permissions for the group owning the file. The group has permissions only for read and execute, but not to write. The final group of permissions belongs to all other users. They can also read and execute, but not write.
To change permissions on a file, you will need to use the chmod command with a few options besides rwx. The following symbols identify the user or group of users you want to change the permissions.
To designate the owner, use a ” u “. For the group, use “ g ” and for all others, you have to use “ o “. For all users and groups, you need to use an “ a ” option. To add permissions, use ” + “, and to take permissions away use ” – “. Let’s see how it works.
Examples:
chmod a+r filename - allow read permissions to everyone.
chmod go-w filename - deny write permissions to the group and others.
chmod a+rwx filename - give full access to everyone.
chmod o-rw filename – deny read and write permissions to others.
Another easier way to change permissions is to use numbers that represent read, write, and execute. See the following list:
# Permission
7 Full
6 Read and write
5 Read and execute
4 Read only
3 Write and execute
2 Write only
1 Execute only
0 None
A sample command would look like the following:
chmod 777 filename - allow everyone to read write and execute the file.
chmod 755 filename - gives the owner full access to the file , the group read and execute the file and the others also read and execute the file.
As you can see there are three digits in a command. The first digit refers to the owner permitions, the second to the group and the third refers to all other users. I think this method is easier because here you don’t need to use the “+” and “-” symbols in order to add or remove permitions.



