LINUX如何修改文件和文件夹的权限_LINUX修改文件夹权限方法

Linux permissions are quite complicated. You need to use these commands: chmod, chown, setfacl.
Let's talk about chmod first. That's the core. There are two modes: symbolic mode and numeric mode.
How do I check current permissions? Just use ls -l, e.g.例如。
ls -l test.txt. That is -rwxr-xr-x, the first rwx is the owner, the second r-x is the group, and the third r-x is everyone else.知道了?
Icon mode is pretty fun. If you want to add execute permissions to the owner, chmod u+x test.txt. Remove write permission from the chmod g-w test.txt group. To enable read and write access for others, use chmod o+rw test.txt.容易,对吧?
What about digital mode?你必须记住这一点。
4 is for reading, 2 is for writing and 1 is for executing. Add it up. Example: 7 5 5 , the owner is 7 (4 +2 +1 ), the group and others are 5 (4 +1 ). So chmod 7 5 5 test.txt, anyone can read it and the owner can write and run it. What about 6 4 4 ? Owners 6 (4 +2 ), others 4 (4 ). chmod 6 4 4 test.txt, everyone can only read it and the owner can write it.
Then -R, recursive. For example, if you want to change a directory and all subdirectory files to 7 5 5 , type chmod -R 7 5 5 foldername. This is very important and is used frequently.
Sometimes just changing permissions isn't enough. For example, if you want to give a file to a specific user, you need to use chown. For example, pass chown user1 test.txt to user1 . If you want to give it to a specific group, chown :groupname test.txt. How about two together? chown user1 :groupname test.txt. After making the changes, you may need to change chmod, e.g.例如。
chmod 6 4 0 test.txt.
The last set facl is expanded. Ordinary permissions are not enough. If you want to set permissions for many people, use this option. First make sure the file system supports this, mount | grep acl to see. Install the ACL package, e.g.例如。
sudo apt install acl on Ubuntu.
The setup is easy. To grant read and write permissions to a user, set facl -m u:user1 :rwx test.txt. Grant the group execute permission setfacl -m g:group1 :x test.txt. For directories setfacl -R -m u:user1 :rwx folder name.
Attention, be careful when doing these operations. Do not make random changes, especially to system files. It's best to give the directory execute permission, otherwise you won't be able to enter it. Setfacl -d can be used to set the default, otherwise new files will not have permissions.

linux修改文件权限命令是什么

I remember once when I was organizing project files on a company server, a certain file was accidentally edited with the wrong permissions, preventing other colleagues from accessing it normally. I opened the terminal and entered the "ls -l" command and found that the file's permissions are shown as "-rw-r--r--", which means that only the owner of the file has read and write permissions, while other users can only read. This clearly does not meet our project collaboration needs.
I immediately thought I should add write permissions for other users. So, I entered the "chmod o+w file.txt" command. After it's done, check the file permissions again and the permissions have changed to "-rw-rw-r--", and other users now have write permission.
This process made me realize that license management is critical to achieving security and team collaboration. A small permission error can affect the progress of the project. This also makes me pay more attention to command line tasks, because they often solve real problems.等等,还有一件事。
I suddenly saw that if the permissions are not set correctly, it can cause a security problem.