How do I change the permissions on files and directories on Linux?
How to change the permissions of files and directories on your Linux system. All commands and examples cited should run from the command line in a terminal. They also say that there are programs in graphic mode where you can get the same thing here is the mouse.
The first thing to say is that to get all the information on the commands involved in the issue of permits you can see the command man chmod, man and man chown chgrp
Information from a file / directory
When you get information about a file / directory with the ls command, there are different fields that you say what kind of permits the file / directory has.
Example:
[user @ localhost] # ls-l
-rwxr-x --- 1 pepito depart1 4348 Nov 24 16:19 test
In the first column you can see a series of letters and-rwxr-x ---, these letters tell us who in the system and that has the kinds of file permissions test.
These letters are grouped into three groups with three positions each, plus a first position to tell us what kind of file it is (the more normal (d) directories, or (-) data files). In our example the first position is (-) bringing the test file is a data file (binary / executable in this example).
The first group of three (in our case rwx) tells us what kind of permits is the owner of the file (u) (user / owner)
The second group of three (rx in our case) tells us that class is the group's permissions file (g) (group).
And the last group three (--- in our case) tells us what kind of permits have all other users of the system on this
file (or) (others).
r means permission to read
w means permission to write
x means permission to execute
The second column pepito, tells us who owns the file (seeds in this case).
The third column depart1, says the group is in the file (depart1 in this case).
The fourth column 4348, says the file size.
The fifth column Nov 24 16:19 tells us what the date and time of last modification.
The sixth column test, which he says is the name of the file / directory.
Thus, the test file of our example has the following permissions:
* Pepito can read, write / modify, and execute the file test.
* Users in the group depart1 can read and execute but not write / modify.
* Other users can not do anything, not read or write / edit, or run it.
How to change the permissions / owner / group of a file / directory?
To change the owner of the file using the command: chown user file
To change the group from using the file command: chgrp group file
To change the permissions using the command: chmod file permissions
The permits can be specified in different ways, a number of examples, the better to understand:
chmod ugo + rwx test (da rwx permissions to all user, group, others)
chmod ugo-x test (x removes permission (execution) for all user, group, others)
chmod o-rwx test (rwx permission to remove others)
chmod u = rwx, g = rx test (a user gives permission rwx, rx a group and none in others)
So we can continue with all possible combinations of letters, is a matter of using the imagination ;-)
There is another method that uses numbers, instead of letters to assign permissions, the following table can help us understand a little like this:
r w x DECIMAL VALUE
0 0 0 0 (000 binary is in decimal 0)
0 0 1 1 .........
0 1 0 2 .........
0 1 1 3 .........
1 0 0 4 (100 binary is 4 in decimal)
1 0 1 5 .........
1 1 0 6 .........
1 1 1 7 (111 binary is 7 in decimal)
1 means on and off 0 or 101 active ryx and disables w. Knowing this only have to use the decimal value to permit only read and execution, a clear example of this.
chmod 750 test
rwx permissions gives the user (7 = 111)
r-x gives permission to the group (5 = 101)
--- gives permission to the other (0 = 000)
That's it for today, hope you have a little more clear what the permissions of files in Linux and you go to lose their fear of the command line.