Linux文件权限修改命令chmod讲解

Oops, chmod was a h3 deal when I first learned Linux. Let me tell you about the pitfalls I have stepped into.
Suppose before last year, I was working on a project on the server.有一个脚本文件script.sh。
I wanted everyone to be able to run it, so I created a chmod 7 7 7 script.sh.结果? Because the operation and maintenance person next door had too many permissions, any user could change the content of the script, and the project finally collapsed. Therefore, when it comes to permissions, you should not wave your hands.
Number mode and symbol mode, I was confused at first. The digital mode looks simple, but you have to remember r=4 w=2 x=1 every time, which is easy to remember incorrectly.后来我主要用的是符号模式。
I added permissions chmod u+x and changed permissions chmod g-w.看上去赏心悦目多了。
然而,数字模式有时很方便。
For example, if the files in your entire directory are 6 4 4 and the directory is 7 5 5 , you can directly do chmod 7 5 5 -R directory_name and it will be easier to do this than changing them one by one.
The most annoying thing is recurring revisions. I remember once I accidentally typed chmod -R 7 7 7 /. My hand shook and I almost changed the permissions of the entire site. I was so scared that I immediately did sudo find / -type d -exec chmod 7 5 5 {} \; -o -type f -exec chmod 6 4 4 {} \;要把它改回来。
So, when using recursion, you have to keep an eye on it.
There is also Umask, which is also easy to ignore.我有一个同事。
Every time he creates a new file, the permission is 6 6 6 . As a result, the umask is 002 2 , so the new该文件的实际权限是6 4 4 因此,必须知道umask,否则权限设置很容易出错。

一般来说,在权限方面需要小心。
不要握手,不要弄乱。
记住最小特权原则,不要向坏人敞开大门。

linux中修改文件权限的命令是

在Linux中,直接使用chmod来调整权限。
例如:chmod 7 5 5 文件名、所有者的读写执行、组的读取执行等。
chown 直接更改文件所有者。
例如:chown 新所有者:新组文件名。
chgrp 直接更改文件所属的组。
例如:chgrp 新组文件名。
根据具体情况选择,不要混用。