Today I'm going to use chmod to make a note of how to set it when changing file permission settings. chmod means change mode, which is the basic of UNIX-like commands. It is used when changing the authority. A common pattern is "chmod 777 file name" for the time being. The error that occurred due to the authority will disappear, but I think that it is quite bad in terms of security, so ... So, I will summarize it so that it will not be "777" immediately.
--Meaning of numbers --For the time being 755 --Chown is also suppressed
What does 777 mean?
The first digit is the "owner" authority information The second digit is the authority information of "owning group" The third digit is "Other" authority information
So, 7 is composed of 4 + 2 + 1.
4 = Read permission (r) 2 = Write permission (w) 1 = Execute permission (x)
is. There seems to be a way to remember this number using binary numbers. From the left, with read permission, write permission, and execute permission
111
I will try to line up with. The leftmost digit is the read authority, which is 4 when converted from binary to decimal. Write permission is 2. Execution authority is 1.
You might think that the owner is the owner, but it's simply the user who owns the file. You should have entered your username and password when you log in. That username is the owner.
ls -l
In can be confirmed.
I'm not used to hearing about groups. There is also a function to manage users as a group when logging in on the PC.
cat /etc/group
You can see how the group exists with this command.
Group name: Password: Group ID: User list It is displayed like this, but by default it is full of unfamiliar groups lol
By being managed by this group, you can change whether to apply the second digit authority. This owning group too
ls -l
In can be confirmed.
Then, "Other" is easy to understand. When you log in as a user who is neither the owning user nor the user of the owning group. For others, I think it's always a good idea to keep the numbers relatively low.
I will try to find out if 755 can be applied for the time being. With this, "Only the owner can write." It means that However, it feels like anyone can check and execute the contents other than writing.
If you think about it based on this, it's good because the meaning of the numbers is sometimes included.
For example, when playing with Laravel
PHP Fatal error: ~~~ could not be opened: failed to open stream: Permission denied'
There are times when Laravel says that I couldn't write because of my permissions. (In my case, I used to generate logs under storage, etc.)
In such a case, make it the property of apatch or nginx (because you log in as a web server) or create a new group and change the group authority to 7. In this case it's 775.
I hope that it can be changed in some cases like this.
Use the chown command to change the "ownership" of the first two digits of the owner and owning group part.
chown new user directory or file chgrp new group directory or file
You can now change the owner or owning group. You can use it when you play with the first two digits!
Recommended Posts