一、文件的权限和归属
二、设置文件或目录的权限 chmod 命令
三、设置文件的归属 chown 命令
四、权限掩码 umask
一、文件的权限和归属
1、访问权限
(1)读权限r
(2)写权限w
(3)可执行x
2、归属(所有权)
(1)属主:拥有该文件的用户账号
(2)属组:拥有该文件的组账号
3、查看文件的权限和归属
例
[root@localhost ~]# ls -l diaochan.txt
-rw-r–r--. 1 root root 0 3月 13 12:40 diaochan.txt
*二、设置文件或者目录的权限 chmod 命令
例
[root@localhost ~]# mkdir /aaa/
[root@localhost ~]# touch /aaa/test{1…3}.txt
[root@localhost ~]# ll /aaa
总用量 0
-rw-r–r--. 1 root root 0 3月 13 12:48 test1.txt
-rw-r–r--. 1 root root 0 3月 13 12:48 test2.txt
-rw-r–r--. 1 root root 0 3月 13 12:48 test3.txt
[root@localhost ~]# chmod u+x,g+w,o-r /aaa/test1.txt
[root@localhost ~]# ll /aaa/test1.txt
-rwxrw----. 1 root root 0 3月 13 12:48 /aaa/test1.txt
[root@localhost ~]# chmod a=rwx /aaa/test2.txt
[root@localhost ~]# ll /aaa/test2.txt
-rwxrwxrwx. 1 root root 0 3月 13 12:48 /aaa/test2.txt
[root@localhost ~]# chmod a-x /aaa/test2.txt
[root@localhost ~]# ll /aaa/test2.txt
-rw-rw-rw-. 1 root root 0 3月 13 12:48 /aaa/test2.txt
[root@localhost ~]# chmod 777 /aaa/test3.txt
[root@localhost ~]# ll /aaa/test3.txt
-rwxrwxrwx. 1 root root 0 3月 13 12:48 /aaa/test3.txt
[root@localhost ~]# chmod 000 /aaa/
[root@localhost ~]# ll -d /aaa/
d---------. 2 root root 4096 3月 13 12:48 /aaa/
[root@localhost ~]# ll /aaa/
总用量 0
-rwxrw----. 1 root root 0 3月 13 12:48 test1.txt
-rw-rw-rw-. 1 root root 0 3月 13 12:48 test2.txt
-rwxrwxrwx. 1 root root 0 3月 13 12:48 test3.txt
[root@localhost ~]# chmod -R 000 /aaa/
[root@localhost ~]# ll /aaa/
总用量 0
----------. 1 root root 0 3月 13 12:48 test1.txt
----------. 1 root root 0 3月 13 12:48 test2.txt
----------. 1 root root 0 3月 13 12:48 test3.txt
[root@localhost ~]# mkdir -m 777 /bbb
[root@localhost ~]# ll -d /bbb
drwxrwxrwx. 2 root root 4096 3月 13 12:55 /bbb
三、设置文件的归属 chown 命令
1、格式
例
[root@localhost ~]# useradd user1
[root@localhost ~]# useradd user2
[root@localhost ~]# useradd user3
[root@localhost ~]# touch {1…3}.txt
[root@localhost ~]# ll *.txt
-rw-r–r--. 1 root root 0 3月 13 13:00 1.txt
-rw-r–r--. 1 root root 0 3月 13 13:00 2.txt
-rw-r–r--. 1 root root 0 3月 13 13:00 3.txt
-rw-r–r--. 1 root root 0 3月 13 12:40 diaochan.txt
[root@localhost ~]# chown user1 1.txt
[root@localhost ~]# ll 1.txt
-rw-r–r--. 1 user1 root 0 3月 13 13:00 1.txt
[root@localhost ~]# chown :user2 2.txt
[root@localhost ~]# ll 2.txt
-rw-r–r--. 1 root user2 0 3月 13 13:00 2.txt
[root@localhost ~]# chown user3:user3 3.txt
[root@localhost ~]# ll 3.txt
-rw-r–r--. 1 user3 user3 0 3月 13 13:00 3.txt
四、权限掩码 umask
1、作用:控制新建的文件或目录的权限
2、umask值与新建文件、目录权限对照表
3、查看umask值
(1)格式:umask
例
[root@localhost ~]# umask
0022
4、设置umask值
(1)格式:umask nnn
例
[root@localhost ~]# umask 010
[root@localhost ~]# umask
0010
实验补充:
1、对于访问权限的理解,主分文件和文件夹
2、对于命令的运用多多练习
3、ls -l 与ll 命令效果一样(在查看文件权限时不一样)
Linux系统管理—权限及归属管理
最新推荐文章于 2025-03-31 23:29:34 发布
