20181122基本权限UGO

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了20181122基本权限UGO相关的知识,希望对你有一定的参考价值。

基本权限UGO

文件权限设置:可以属于某个用户或组,能够以何种方式访问某个文件
[[email protected] ~]# ll list1.txt
-rw-r--r--. 1 root root 2946 11月 2 10:00 list1.txt
root用户:读写 rw
root组成员:读 r
其他用户:读 r

权限对象:
属主:U
属组:G
其他人:O

权限类型:
读:R 4
写:W 2
执行:X 1
一.设置权限
1.更改文件的属主、属组
chown:
[[email protected] ~]# chown alice list2.txt #将这个文件的所有者改为alice
[[email protected] ~]# ll list2.txt
-rw-r--r--. 1 alice root 3002 11月 4 23:46 list2.txt
[[email protected] ~]# chown .it list2.txt #将这个文件的属组改为it
[[email protected] ~]# ll list2.txt
-rw-r--r--. 1 alice it 3002 11月 4 23:46 list2.txt

[[email protected] ~]# chown -R dong1.it dir1 将目录及目录下的文件都改为 dong1 it组
[[email protected] ~]# ll -d dir1
drwxr-xr-x. 2 dong1 it 4096 10月 7 20:01 dir1
[[email protected] ~]# ll dir1
总用量 0
-rw-r--r--. 1 dong1 it 0 10月 7 20:01 file1

2.更改权限
技术分享图片
[[email protected] ~]# chmod g+x list2.txt 给属组增加执行权限
[[email protected] ~]# ll list2.txt
-rw-r-xr--. 1 alice it 3002 11月 4 23:46 list2.txt
[[email protected] ~]# chmod g+w list2.txt 给属组增加写权限
[[email protected] ~]# ll list2.txt
-rw-rwxr--. 1 alice it 3002 11月 4 23:46 list2.txt

[[email protected] ~]# chmod u=rwx,g=rw,o=r list2.txt 属主rwx 组rw 其他r
[[email protected] ~]# ll list2.txt
-rwxrw-r--. 1 alice it 3002 11月 4 23:46 list2.txt

[[email protected] ~]# chmod a+x list2.txt 所有增加X权限
[[email protected] ~]# ll list2.txt
-rwxrwxr-x. 1 504 it 3002 11月 4 23:46 list2.txt
技术分享图片
使用数字
[[email protected] ~]# chmod 777 dir1 更改dir1的权限,全部rwx
[[email protected] ~]# ll -d dir1
drwxrwxrwx. 2 dong1 it 4096 10月 7 20:01 dir1

[[email protected] ~]# chmod 7 dir1 7=007
[[email protected] ~]# ll -d dir1
d------rwx. 2 dong1 it 4096 10月 7 20:01 dir1

二.设置权限案例:
针对hr部门的访问目录/home/hr设置权限,要求如下:
1.root用户和hr组的员工可以读、写、执行
2.其他用户没有任何权限
[[email protected] ~]# groupadd hr 新建一个组hr
[[email protected] ~]# useradd hr01 -G hr 新建成员并加入hr组
[[email protected] ~]# useradd hr02 -G hr
[[email protected] ~]# mkdir /home/hr 创建目录
[[email protected] ~]# chgrp hr /home/hr 将这个目录的组改为hr
[[email protected] ~]# ll -d /home/hr
drwxr-xr-x. 2 root hr 4096 11月 5 05:54 /home/hr
[[email protected] ~]# chmod 770 /home/hr 修改目录的权限
[[email protected] ~]# ll -d /home/hr
drwxrwx---. 2 root hr 4096 11月 5 05:54 /home/hr

实战案例一:rwx對文件的影響
[[email protected] ~]# vim /home/file2
date
[[email protected] ~]# ll /home/file2
-rw-r--r--. 1 root root 5 11月 5 06:14 /home/file2

[[email protected] ~]# cat /home/file2 其他用戶測試讀
date
[[email protected] ~]$ /home/file2 測試執行
-bash: /home/file2: 权限不够

[[email protected] ~]# chmod o+x /home/file2 增加權限
[[email protected] ~]$ /home/file2 再次測試
2018年 11月 05日 星期一 06:17:42 CST

[[email protected] ~]# chmod o+w /home/file2增加寫權限
[[email protected] ~]$ vim /home/file2 測試寫
date
ls
实战案例二:rwx對目錄的影響
[[email protected] ~]# touch /dir10/file1
[[email protected] ~]# chmod 777 /dir10/file1
[[email protected] ~]# ll /dir10/file1
-rwxrwxrwx. 1 root root 0 11月 5 06:29 /dir10/file1
[[email protected] ~]# ll -d /dir10
drwxr-xr-x. 2 root root 4096 11月 5 06:24 /dir10

[[email protected] ~]$ rm /dir10/file1 無法刪除
rm: 无法删除"/dir10/file1": 权限不够

[[email protected] ~]# chmod o+w /dir10 對目錄增加寫權限

[[email protected] ~]$ rm /dir10/file1
[[email protected] ~]$ cd /dir10 已經刪除了
[[email protected] dir10]$ ls
[[email protected] dir10]$
對目錄有W權限,可以在目錄中創建新文件,可以刪除目錄中的文件(與文件權限無關)

以上是关于20181122基本权限UGO的主要内容,如果未能解决你的问题,请参考以下文章

liunx-系统配置及服务管理 用户的权限-基本权限UGO

Linux权限管理基本知识

linux权限管理之基本权限

Linux-文件权限

五大权限:UGO权限SetUID SetGID StickyACL权限chattr(文件系统级别的权限)SELINUX

Linux 用户身份与进程权限