Issue
After a lot of reading, I still don't understand how to use chmod. My main question is what do the numbers mean? I am new to Unix and am doing some emergency fixes on our web server and am being asked to fix the permissions for some files. I don't understand what I need to do to make the files accessible.
Can someone provide some help here?
EDIT: Thanks for the great answers everyone. Unfortunately, I was in a panic and didn't read them in time and we ended up losing our client.. Hard to choose any single answer but I chose the one that I understood best.
Solution
You have 3 permission types:
- User (permissions applying to the file's owner)
- Group (permissions applying to the file's group)
- Other (permissions applying to everyone else)
For each of these types, you can allow 3 things:
- Ability to read (note that you need read permissions on a directory to list it)
- Ability to write
- Ability to execute
If you say:
chmod 755 some_file
It gets broken down like this:
User Group Other
7 5 5 (octal value, base-8)
111 101 101 (binary value, base-2 or binary)
RWX RWX RWX
where: R - Read, W - Write, X - eXecute
So that command would mean that the owner gets all permissions, but group members, and others can only read and execute.
There's another input format with chmod that's handy, and doesn't require you to do conversion to binary in your head. As an example, to add execute permission for user:
chmod u+x some_file
To remove those permissions, you would say
chmod u-x some_file
You can replace 'u' with 'u', 'g', or 'o' (user, group, other respectively), and 'x' with 'r', 'w', or 'x' (you get the idea).
You have to be careful with this. If you did:
chmod -R 777 some_directory
And that file contained sensitive configuration data, then you just gave 'other' (i.e. the outside world) full read permissions (meaning the web server may serve up this information).
It would also be worthwhile for you to have a look at the chown
command as well.
Answered By - user3738848