基本权限 UGO

来源:互联网 发布:mac os 壁纸 编辑:程序博客网 时间:2024/05/19 21:01

 

基本权限 UGO


========================================================

文件权限设置: 可以赋于某个用户或组 能够以何种方式 访问某个文件

文件权限管理之:UGO设置基本权限(r、w、x)
rw-r--r-- alice hrinstall.log

权限对象:
属主: u
属组: g
其他人: o

权限类型:
读:r 4
写:w 2
执行: x 1

===设置权限
1. 更改文件的属主、属组
=chown
[root@tianyun ~]# chown alice.hr file1 //改属主、属组
[root@tianyun ~]# chown alice file1 //只改属主
[root@tianyun ~]# chown .hr file1 //只改属组
=chgrp
[root@tianyun ~]# chgrp it file1 //改文件属组
[root@tianyun ~]# chgrp -R it dir1 //改文件属组

2. 更改权限
=a. 使用符号
对象 赋值符 权限类型
u + r
chmod g - w file1
o = x
a
[root@tianyun ~]# chmod u+x file1 //属主增加执行
[root@tianyun ~]# chmod a=rwx file1 //所有人等于读写执行
[root@tianyun ~]# chmod a=- file1 //所有人没有权限
[root@tianyun ~]# chmod ug=rw,o=r file1 //属主属组等于读写,其他人只读
[root@tianyun ~]# ll file1 //以长模式方式查看文件权限
-rw-rw-r-- 1 alice it 17 10-25 16:45 file1 //显示的结果

=b. 使用数字
[root@tianyun ~]# chmod 644 file1
[root@tianyun ~]# ll file1
-rw-r--r-- 1 alice it 17 10-25 16:45 file1


===设置权限示例
针对hr部门的访问目录设置权限,要求如下:
1. root用户和hr组的员工可以读、写、执行
2. 其他用户没有任何权限
[root@tianyun ~]# groupadd hr
[root@tianyun ~]# useradd hr01 -G hr
[root@tianyun ~]# useradd hr02 -G hr
[root@tianyun ~]# mkdir /home/hr

[root@tianyun ~]# chgrp hr /home/hr
[root@tianyun ~]# chmod 770 /home/hr
[root@tianyun ~]# ll -d /home/hr/
drwxrwx---. 2 root hr4096 3月 13 14:26 /home/hr/

重要: r、w、x权限对文件和目录的意义




示例1对文件的影响
[root@tianyun ~]# mkdir /dir10
[root@tianyun ~]# touch /dir10/file1
[root@tianyun ~]# chmod 777 /dir10/file1

[root@tianyun ~]# ll -d /dir10/
drwxr-xr-x. 2 root root 4096 3月 11 18:37 /dir10/
[root@tianyun ~]# ll /dir10/file1
-rwxrwxrwx. 1 root root 0 3月 11 18:37 /dir10/file1

[alice@tianyun ~]$ cat /dir10/file1
[alice@tianyun ~]$ rm -rf /dir10/file1
rm: 无法删除"/dir10/file1": 权限不够

示例2对目录有w权限
[root@tianyun ~]# chmod 777 /dir10/
[root@tianyun ~]# chmod 000 /dir10/file1
[root@tianyun ~]# ll -d /dir10/
drwxrwxrwx. 2 root root 4096 3月 11 18:37 /dir10/
[root@tianyun ~]# ll /dir10/file1
----------. 1 root root 0 3月 11 18:37 /dir10/file1

[alice@tianyun ~]$ cat /dir10/file1
cat: /dir10/file1: 权限不够
[alice@tianyun ~]$ rm -rf /dir10/file1
[alice@tianyun ~]$ touch /dir10/file2

问题1
[root@tianyun ~]# ll /root/install.log
-rw-r--r--. 1 root root 46571 6月 1 23:37/root/install.log
[alice@tianyun ~]$ cat /root/install.log
cat: /root/install.log: 权限不够

问题2:alice能删除/下的任何文件吗?
[root@tianyun ~]# chmod 777 /
[root@tianyun ~]# ll -d /
drwxrwxrwx. 27 root root 4096 6月 4 11:32 /
[alice@tianyun ~]$ rm -rf /etc






 

 

 

原创粉丝点击