First of all, let's figure out what the command "chmod" does.
chmod - The chmod command allows you to alter access rights to files and directories. All files and directories have security permissions that grant the user particular groups’ or all other users’ access. To view your files' settings, at the shell prompt type: ls -alt
You should see some files with the following in front of them (an example follows):
total 4
drwxrwsr-x 7 file1 file1 1024 Apr 6 14:30 .
drwxr-s--x 22 file2 file2 1024 Mar 30 18:20 ..
d-wx-wx-wx 3 file3 file3 1024 Apr 6 14:30 content
drwxr-xr-x 2 file4 file4 1024 Mar 25 20:43 files
What do the letters mean in front of the files/directories mean?
r indicates that it is readable (someone can view the file’s contents)
w indicates that it is writable (someone can edit the file’s contents)
x indicates that it is executable (someone can run the file, if executable)
- indicates that no permission to manipulate has been assigned.
When listing your files, the first character lets you know whether you’re looking at a file or a directory. It’s not part of the security settings. The next three characters indicate Your access restrictions. The next three indicate your group's permissions, and finally other users' permissions.
Use chmod followed by the permission you are changing. In very simple form this would be:
chmod 755 filename
The example above will grant you full rights, group rights to execute and read, and all others access to execute the file.
# 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
Still confused? Use the table above to define the settings for the three "users." In the command, the first number refers to your permissions, the second refers to group, and the third refers to general users.
Typing the command: chmod 751 filename
gives you full access, the group read and execute, and all others execute only permission.
I hope this article helps anyone having trouble with file permissions on linux. Don't forget to rate and comment. Thanks.
-ScrAm
Cast your vote on this article *Note: the order of the votes has been reversed.
I would have made it a little more in depth. Why does 7 mean full permisions? It is because of the following reason:
If you would heave all permissions, you would have read, write and execute permissions so rwx. We could use the number 1 to say you have a certain permission, and 0 to say you have not. If you have all permission, it would look like the following:
r|w|x
1|1|1
111 is binary. Converting this to the decimal system makes 7. If you only had read and execute permissions, it would look like this:
r|w|x
1|0|1
101 is 5 in decimal.
So 777 means \"give all permissions to the owner, to the group, and to the others.\"
minor point/stupid question i expect:
in the second line of the example
(drwxr-s--x 22 file2 file2 1024 Mar 30 18:20 ..)
i take it the 's' is a mistype? or does s have some kindof mystery function...
This site is the collective work of the
HackThisSite staff. Please don't reproduce in part or whole without permission.
Page Generated: Fri, 21 Nov 2008 08:38:42 -0500 Exec:
10 Page loaded in 0.21492 seconds!
I would have made it a little more in depth. Why does 7 mean full permisions? It is because of the following reason:
If you would heave all permissions, you would have read, write and execute permissions so rwx. We could use the number 1 to say you have a certain permission, and 0 to say you have not. If you have all permission, it would look like the following:
r|w|x
1|1|1
111 is binary. Converting this to the decimal system makes 7. If you only had read and execute permissions, it would look like this:
r|w|x
1|0|1
101 is 5 in decimal.
So 777 means \"give all permissions to the owner, to the group, and to the others.\"
Beside that, it is a good article. 7/10