[Linux] Basics of authority setting by chmod for beginners

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

Meaning of numbers

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.

For the time being 755

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.

Also supports chown and chgrp

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

[Linux] Basics of authority setting by chmod for beginners
[Must-see for beginners] Basics of Linux
[For beginners] Basics of Python explained by Java Gold Part 2
[For beginners] Basics of Python explained by Java Gold Part 1
Basics of pandas for beginners ② Understanding data overview
Linux distribution recommended for beginners
Seaborn basics for beginners ④ pairplot
Linux command memorandum [for beginners]
Convenient Linux shortcuts (for beginners)
■ Kaggle Practice for Beginners --Introduction of Python --by Google Colaboratory
Pandas basics for beginners ④ Handling of date and time items
Pandas basics for beginners ① Reading & processing
[Linux Nginx] Command collection used for initial setting of Web server
Pandas basics for beginners ⑧ Digit processing
Seaborn basics for beginners ① Aggregate graph of the number of data (Countplot)
Frequently used Linux commands (for beginners)
A story that is a little addicted to the authority of the directory specified by expdp (for beginners)
Implementation example of hostile generation network (GAN) by keras [For beginners]
Pandas basics summary link for beginners
Learn the basics of Python ① Beginners
Python learning memo for machine learning by Chainer Chapter 13 Basics of neural networks
[Python] Minutes of study meeting for beginners (7/15)
[Learning memo] Basics of class by python
Django tutorial summary for beginners by beginners ③ (View)
Linux operation for beginners Basic command summary
3 Config editing mistakes made by Linux beginners
[Linux setting series] Prompt setting of bash. / prompt / bash / shell
Pandas of the beginner, by the beginner, for the beginner [Python]
[Linux] Change of authority, owner, owning group
[Linux] Learn the basics of shell commands
Django tutorial summary for beginners by beginners ⑤ (test)
A textbook for beginners made by Python beginners
For beginners of SageMaker --Collection of material links -
Linux basics
Linux basics
Easy-to-understand explanation of Python Web application (Django) even for beginners (3) [Application creation / DB setting]
[Linux] Review of commands for deploying on AWS
[Linux command] cp command option list [Must-see for beginners]
[Linux command] ls command option list [Must-see for beginners]
Pandas basics for beginners ③ Histogram creation with matplotlib
[Linux command] touch command option list [Must-see for beginners]
Django tutorial summary for beginners by beginners ⑦ (Customize Admin)
[Linux command] less command option list [Must-see for beginners]
An introduction to object-oriented programming for beginners by beginners
Django tutorial summary for beginners by beginners ⑥ (static file)
2-2. Input for becoming a WEB engineer (Linux basics)
[Linux command] cat command option list [Must-see for beginners]
Django Tutorial Summary for Beginners by Beginners (Model, Admin)
Django tutorial summary for beginners by beginners ① (project creation ~)
[Linux command] pwd command option list [Must-see for beginners]
[Linux command] cd command option list [Must-see for beginners]
[Linux command] mv command option list [Must-see for beginners]
Easy understanding of Python for & arrays (for super beginners)
About Nim higher-order functions for Nim beginners written by Nim beginners
[Linux command] man command option list [Must-see for beginners]
Django tutorial summary for beginners by beginners ④ (Generic View)
Convenient tool for beginners (under consideration of ideas)
[Linux command] ssh command option list [Must-see for beginners]
Basic principles of image recognition technology (for beginners)
[Python for Hikari] Chapter 09-01 Classes (Basics of Objects)
[Linux command] mkdir command option list [Must-see for beginners]