Today I will explain about permissions. I think the concept of permissions is unfamiliar to anyone using Windows. What is it like?
Files have permissions on Linux. Permissions are the permissions on a file. You can specify who can do what with permissions.
For example, the owner can read and write to this file, the group can also read and write, and other users can only read.
It is easy to check the permissions by using the ls command to display the file details.
-rw-rw-r-- 1 kimoto kimoto 588 Jun 16 13:19 README drwxrwxr-x 3 kimoto kimoto 4096 Jun 16 16:39 lib
The permissions are "rw-rw-r--" and "rwxrwxr-x" excluding the leftmost character. By the way, the one character on the far left indicates the type of file. If you say d, you know that the file is a directory. (In Linux, it is considered as one file type in the directory.)
Owner user, owner group, guest user
Permission consists of three parts. Each set of 3 characters is one set.
The following permissions are first divided into three parts.
# User Permission rw- # Group Permission rw- # Guest Permission r--
The first 3 letters are for the owner user, the next 3 letters are for the owner group, and the last 3 letters are for the non-owner user.
r is read permission, w is write permission, x is execute permission
Next, I will explain the meaning of the characters rwx . If you have read permission, the first character is r, if you have write permission, the second character is w, and if you have execute permission, the third character is x.
For example, it will be as follows.
rwx read, write, execute permissions rw- read and write permissions r-- read permission r-x read permission, execute permission
Execution permission is a flag that indicates whether the file can be executed as an application. For example, if you create a program, you will have execute permission. Also, keep in mind that in the case of a directory, you cannot read the files contained in the directory without execute permission.
Generally speaking, a directory always has execute permission x.
Change of owner chown
Remember how to change the owner of a file. Use chown .
chwon UserName FileName
The following sample is an example of changing the owner user of the file foo.txt to kimoto.
chown kimoto foo.txt
You can also change the owner group as well.
chown UserName:GroupName FileName
The following sample is an example of changing the owner user of the file foo.txt to kimoto and the owner group to someproject.
chown kimoto:someproject foo.txt
How to set permissions chmod
The permission setting method is a little complicated. Permissions are set in octal. Let's remember the following correspondence. For the time being, let's remember only the following measures.
Binary Octal rwx 111 7 rw- 110 6 r-x 101 5 r-- 100 4 --- 000 0
Please take a closer look. The position where the bit is set in the binary number corresponds to the position of rwx. This is expressed in octal and the permissions are specified.
For example, suppose you want to specify permissions as follows.
In such a case, use the chmod command as follows.
chmod 755 foo.txt
Rwx is 7, r-x is 5, so "rwxr-xr-x" is 755.
Only one more sample.
In this case, it will be as follows.
chmod 644 foo.txt
Since rw- is 6 and r-- is 4, "rw-r--r--" is 644.
Well, I think you will gradually be able to understand it with a sense. You're used to it.