File permissions in Linux are actually pretty easy to understand and modify. To check the permissions on a file just navigate to the directory and use the following command to list the files and their details.
ls -l
As you can see, the first piece of information on each line are the permissions. There are 3 sets of permissions put together all into one line. The very first character denotes whether the file is a directory, a link or a file.
- = file
l = symbolic link
d = directory
The 3 characters following the first character represent the permission information for the file owner. The 3 characters following that denote the permissions for the group and the last 3 characters are the file permissions for everyone else. A key for what the characters mean is listed below:
- = no read, write, or execute permissions
r = read
w = write
x = execute
For example, lets say we have the following permission information on a file.
drwxr-xr-x
Since the first character is “d” we know that its a directory. Then next 3 characters are “rwx” which means that the owner has read, write, and execute permissions. The next set of characters are “r-x” which means the group has read and execute permissions but no write permissions. The last 3 characters are “r-x” which means that everyone else has read and execute permissions but no write permissions.
You can easily change file permissions by using the “chmod” command. Using numbers to change permissions on a file is very quick, easy, and precise. A key for what each number represents is listed below.
4 = read
2 = write
1 = execute
You have to set permissions for the owner, group, and everyone else all at the same time when using the number method so that means there will be 3 numbers. The first number is the permission for the owner, the second is for the permission of the group and the last number is the file permission for everyone else.
To give the owner, group, and everyone else only read permissions then the command would be the following.
chmod 444 filename
To give the owner, group, and everyone else read and execute permission then you just add the numbers together. So 4(read) + 1(execute) = 5.
chmod 555 filename
The numbers don’t have to be the same, you can give different permissions to the owner, group and everyone else all in one shot. So lets say you want the file owner to have read, write and execute permissions but you want the group and everyone else to have only read and execute permissions. The command to do this would be the following.
chmod 755 filename
If you are applying permissions to a folder and would like to recursively change the permissions of the contents as well then don’t forget to use the capital ‘R’ switch:
chmod -R 755 somedir
Remember, the first digit is for the owner, the second digit is for the group and the last digit is for everyone else.
how do i give read and write permissions to everybody so i don’t ever have any issues with permissions?
That cleared up a lot of things..lol..thanks
Jayton,
To give full permissions to everyone then you can do a chmod 777. This will give you read, write and execute permission to everyone.
I personally wouldn’t recommend this unless you know exactly what you are doing.
brief yet comprehensive. very useful, thanks a lot.