1. Premise
We need to know Linux
the meaning of the system, everything is a file.
For Linux, everything is a file.
The concepts we often relate to are directories and files.
There are three main types of permissions: r(读)w(写)x(执行)
.
Two, the text
1. Modify the user and group to which the file or directory belongs
chown [用户名[:组名]] [文件或目录]
chown yunwei /home/hello.txt 把hello.txt文件的所有者修改成yunwei。
这样,yunwei账号就可以对这个文件进行编辑。
chown yunwei:yunwei /home/hello.txt 把hello文件的所属用户和所属组同时改成yunwei账号和yunwei组。
如果是嵌套的目录,则需带上-R参数,对子目录及子文件也进行修
改。
chown -R yunwei:yunwei /home/test 对test目录及其子目录及子文件进行所属修改。
2. Modify the group to which a file or directory belongs
chgrp [组名] [文件或目录]
chgrp wudang /home/hello.txt 把hello.txt文件的所属组修改成wudang,
这样,wudang组内的所有用户都可以对这个文件进行编辑
3. Modify the permissions of files or directories
method one:
chmod [ugoa][=+-][rwx] [文件或目录]
No spaces between the first three parameters
chmod u=rwx /home/hello.txt 给所属用户赋予读写执行的权限
chmod g+r /home/hello.txt 给所属组增加读权限
chmod o+r /home/hello.txt 给其他用户增加读权限
chmod a-x /home/hello.txt 给所有用户去除执行权限
同时修改多个的方式:
chmod u=rwx,g+r,a-x /home/hello.txt
Method 2:
Change permissions by number r-4 w-2 x-1
chmod [0-7][0-7][0-7] [文件或目录]
The first digit corresponds to the user to which it belongs, the second digit corresponds to the group it belongs to, and the third digit corresponds to other users
chmod 777 /home/hello.txt
chmod 600 /home/hello.txt
4. Supplementary instructions
File rwx
permissions are well understood.
Read, write, and execute files.
The rwx permission of the directory
x
: it means that you can enter the directory, such as cd.
r
: Indicates that ls can be used to view the files in the directory.
w
: Indicates that files can be deleted or created in this directory.
It is very important to understand the following picture:
you need to know the above commands, and the modified ones correspond to the data in the picture, then you really understand the Linux file permissions.