文件权限
基本权限 UGO
文件权限设置: 可以赋于某个用户或组 能够以何种方式 访问某个文件
文件权限管理之: UGO设置基本权限(r、w、x)
权限对象:
属主: u
属组: g
其他人: o
基本权限类型:
读:r 4
写:w 2
执行: x 1
===设置权限
更改文件的属主、属组
=chown:
[root@xiaochen ~]# chown alice.hr file1 //改属主、属组
[root@xiaochen ~]# chown alice file1 //只改属主
[root@xiaochen ~]# chown .hr file1 //只改属组
[root@xiaochen ~]# chown -R alice.hr dir1
=chgrp:
[root@xiaochen ~]# chgrp it file1 //改文件属组
[root@xiaochen ~]# chgrp -R it dir1 //改文件属组
更改权限
使用符号
对象 赋值符 权限类型
u + r
chmod g - w file1
o = x
a
[root@xiaochen ~]# chmod u+x file1 //属主增加执行
[root@xiaochen ~]# chmod a=rwx file1 //所有人等于读写执行
[root@xiaochen ~]# chmod a=- file1 //所有人没有权限
[root@xiaochen ~]# chmod ug=rw,o=r file1 //属主属组等于读写,其他人只读
[root@xiaochen ~]# ll file1 //以长模式方式查看文件权限
-rw-rw-r-- 1 alice it 17 10-25 16:45 file1 //显示的结果
使用数字
[root@xiaochen ~]# chmod 644 file1
[root@xiaochen ~]# ll file1
-rw-r–r-- 1 alice it 17 10-25 16:45 file1
UGO权限示例
===设置权限示例
针对hr部门的访问目录设置权限,要求如下:
boss用户和hr组的员工可以读、写、执行
其他用户没有任何权限
重要: r、w、x权限对文件和目录的意义
对于文件:
r----------读 cat head tail less more (root用户不受r权限的限制)
w----------写 vim > >> (root用户不受w权限的限制)
x----------执行 ./ 绝对路径 普通执行(rx) 管理员(x)
对于目录: (root用户均不受权限的限制)
r----------ls r 只能读文件名 r-x 文件详细信息
w----------touch rm -wx 创建文件 rwx 删除所有文件
x----------cd
示例
示例1: 对文件的影响
[root@xiaochen ~]# mkdir /dir10
[root@xiaochen ~]# touch /dir10/file1
[root@xiaochen ~]# chmod 777 /dir10/file1
[root@xiaochen ~]# ll -d /dir10/
drwxr-xr-x. 2 root root 4096 3月 11 18:37 /dir10/
[root@xiaochen ~]# ll /dir10/file1
-rwxrwxrwx. 1 777 root 0 3月 11 18:37 /dir10/file1
[alice@xiaochen ~]$ cat /dir10/file1
[alice@xiaochen ~]$ rm -rf /dir10/file1
rm: 无法删除"/dir10/file1": 权限不够
想要删除目录下的文件就必须要对文件所在的目录有写的权限。
示例2: 对目录有w权限
[root@xiaochen ~]# chmod 777 /dir10/
[root@xiaochen ~]# chmod 000 /dir10/file1
[root@xiaochen ~]# ll -d /dir10/
drwxrwxrwx. 2 root root 4096 3月 11 18:37 /dir10/
[root@xiaochen ~]# ll /dir10/file1
----------. 1 root root 0 3月 11 18:37 /dir10/file1
[alice@xiaochen ~]$ cat /dir10/file1
cat: /dir10/file1: 权限不够
[alice@xiaochen ~]$ rm -rf /dir10/file1
[alice@xiaochen ~]$ touch /dir10/file2
如果对上一级目录有写的权限,那么是可以在目录下新建和删除文件的,但是,如果对文件本身没
有什么权限,那么就没有办法看这个文件。如果对文件本身有r的权限,那么就可以看文件了。
基本权限ACL
UGO设置基本权限: 只能一个用户,一个组和其他人
ACL 设置基本权限: r,w,x
=ACL基本用法=
设置:
[root@xiaochen ~]# touch /home/test.txt
[root@xiaochen ~]# ll /home/test.txt
-rw-r–r-- 1 root ro