20181122基本权限UGO

基本权限UGO

文件权限设置:可以属于某个用户或组,能够以何种方式访问某个文件
[root@dong ~]# 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:
[root@dong ~]# chown alice list2.txt #将这个文件的所有者改为alice
[root@dong ~]# ll list2.txt
-rw-r--r--. 1 alice root 3002 11月 4 23:46 list2.txt
[root@dong ~]# chown .it list2.txt #将这个文件的属组改为it
[root@dong ~]# ll list2.txt
-rw-r--r--. 1 alice it 3002 11月 4 23:46 list2.txt

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

2.更改权限
20181122基本权限UGO
[root@dong ~]# chmod g+x list2.txt 给属组增加执行权限
[root@dong ~]# ll list2.txt
-rw-r-xr--. 1 alice it 3002 11月 4 23:46 list2.txt
[root@dong ~]# chmod g+w list2.txt 给属组增加写权限
[root@dong ~]# ll list2.txt
-rw-rwxr--. 1 alice it 3002 11月 4 23:46 list2.txt

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

[root@dong ~]# chmod a+x list2.txt 所有增加X权限
[root@dong ~]# ll list2.txt
-rwxrwxr-x. 1 504 it 3002 11月 4 23:46 list2.txt
20181122基本权限UGO
使用数字
[root@dong ~]# chmod 777 dir1 更改dir1的权限,全部rwx
[root@dong ~]# ll -d dir1
drwxrwxrwx. 2 dong1 it 4096 10月 7 20:01 dir1

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

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

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

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

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

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

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

[root@dong ~]# chmod o+w /dir10 對目錄增加寫權限

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

猜你喜欢

转载自blog.51cto.com/8450442/2320718
今日推荐