微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

linux系统中所属组权限

1、创建测试用户

[root@linuxprobe home]# for i in liujiaxin{01..05};do useradd -g root $i;echo "123456" | passwd --stdin $i;done
##创建测试用户,指定所属组为root,密码为123456 Changing password
for user liujiaxin01. passwd: all authentication tokens updated successfully. Changing password for user liujiaxin02. passwd: all authentication tokens updated successfully. Changing password for user liujiaxin03. passwd: all authentication tokens updated successfully. Changing password for user liujiaxin04. passwd: all authentication tokens updated successfully. Changing password for user liujiaxin05. passwd: all authentication tokens updated successfully. [root@linuxprobe home]# groupadd liujiaxin06 ## 创建组 [root@linuxprobe home]# for i in liujiaxin{06..10};do useradd -g liujiaxin06 $i;echo "123456" | passwd --stdin $i;done
## 创建测试用户,指定所属组为liujiaxin06,密码为123456 Changing password
for user liujiaxin06. passwd: all authentication tokens updated successfully. Changing password for user liujiaxin07. passwd: all authentication tokens updated successfully. Changing password for user liujiaxin08. passwd: all authentication tokens updated successfully. Changing password for user liujiaxin09. passwd: all authentication tokens updated successfully. Changing password for user liujiaxin10. passwd: all authentication tokens updated successfully. [root@linuxprobe home]# for i in liujiaxin{01..10};do id $i;done ## 查看所属组 uid=1001(liujiaxin01) gid=0(root) groups=0(root) uid=1002(liujiaxin02) gid=0(root) groups=0(root) uid=1003(liujiaxin03) gid=0(root) groups=0(root) uid=1004(liujiaxin04) gid=0(root) groups=0(root) uid=1005(liujiaxin05) gid=0(root) groups=0(root) uid=1006(liujiaxin06) gid=1001(liujiaxin06) groups=1001(liujiaxin06) uid=1007(liujiaxin07) gid=1001(liujiaxin06) groups=1001(liujiaxin06) uid=1008(liujiaxin08) gid=1001(liujiaxin06) groups=1001(liujiaxin06) uid=1009(liujiaxin09) gid=1001(liujiaxin06) groups=1001(liujiaxin06) uid=1010(liujiaxin10) gid=1001(liujiaxin06) groups=1001(liujiaxin06)

 

 

 

2、创建测试文件

[root@linuxprobe home]# mkdir test;chmod 777 test;cd test
[root@linuxprobe test]# seq 5 | tee file{01..10}
1
2
3
4
5
[root@linuxprobe test]# chgrp liujiaxin06 file06 file07 file08 file09 file10  ## chgrp命名改变文件所属组
[root@linuxprobe test]# chmod g+w * ## 给所有文件所属组赋予写的权限
[root@linuxprobe test]# ll
total 40
-rw-rw-r--. 1 root root        10 Oct 20 19:48 file01
-rw-rw-r--. 1 root root        10 Oct 20 19:48 file02
-rw-rw-r--. 1 root root        10 Oct 20 19:48 file03
-rw-rw-r--. 1 root root        10 Oct 20 19:48 file04
-rw-rw-r--. 1 root root        10 Oct 20 19:48 file05
-rw-rw-r--. 1 root liujiaxin06 10 Oct 20 19:48 file06
-rw-rw-r--. 1 root liujiaxin06 10 Oct 20 19:48 file07
-rw-rw-r--. 1 root liujiaxin06 10 Oct 20 19:48 file08
-rw-rw-r--. 1 root liujiaxin06 10 Oct 20 19:48 file09
-rw-rw-r--. 1 root liujiaxin06 10 Oct 20 19:48 file10

 

 

 

3、测试不同所属组用户

 

[liujiaxin01@linuxprobe test]$ ll  ## 查看文件所属组、文件所属组的权限
total 40
-rw-rw-r--. 1 root root        10 Oct 20 19:48 file01
-rw-rw-r--. 1 root root        10 Oct 20 19:48 file02
-rw-rw-r--. 1 root root        10 Oct 20 19:48 file03
-rw-rw-r--. 1 root root        10 Oct 20 19:48 file04
-rw-rw-r--. 1 root root        10 Oct 20 19:48 file05
-rw-rw-r--. 1 root liujiaxin06 10 Oct 20 19:48 file06
-rw-rw-r--. 1 root liujiaxin06 10 Oct 20 19:48 file07
-rw-rw-r--. 1 root liujiaxin06 10 Oct 20 19:48 file08
-rw-rw-r--. 1 root liujiaxin06 10 Oct 20 19:48 file09
-rw-rw-r--. 1 root liujiaxin06 10 Oct 20 19:48 file10
[liujiaxin01@linuxprobe test]$ whoami
liujiaxin01
[liujiaxin01@linuxprobe test]$ id liujiaxin01  ## 查看用户所属组
uid=1001(liujiaxin01) gid=0(root) groups=0(root)
[liujiaxin01@linuxprobe test]$ echo "xxxxxx" >> file01
[liujiaxin01@linuxprobe test]$ echo "xxxxxx" >> file02
[liujiaxin01@linuxprobe test]$ echo "xxxxxx" >> file03
[liujiaxin01@linuxprobe test]$ echo "xxxxxx" >> file06
-bash: file06: Permission denied
[liujiaxin01@linuxprobe test]$ echo "xxxxxx" >> file07
-bash: file07: Permission denied
[liujiaxin01@linuxprobe test]$ echo "xxxxxx" >> file09
-bash: file09: Permission denied
## 当文件用户的所属组一致,并且文件的所属组有相应权限时,才具有相应的权限

 

 

 

##同上
[liujiaxin06@linuxprobe test]$ ll total
40 -rw-rw-r--. 1 root root 17 Oct 20 19:53 file01 -rw-rw-r--. 1 root root 17 Oct 20 19:53 file02 -rw-rw-r--. 1 root root 17 Oct 20 19:53 file03 -rw-rw-r--. 1 root root 10 Oct 20 19:48 file04 -rw-rw-r--. 1 root root 10 Oct 20 19:48 file05 -rw-rw-r--. 1 root liujiaxin06 10 Oct 20 19:48 file06 -rw-rw-r--. 1 root liujiaxin06 10 Oct 20 19:48 file07 -rw-rw-r--. 1 root liujiaxin06 10 Oct 20 19:48 file08 -rw-rw-r--. 1 root liujiaxin06 10 Oct 20 19:48 file09 -rw-rw-r--. 1 root liujiaxin06 10 Oct 20 19:48 file10 [liujiaxin06@linuxprobe test]$ whoami liujiaxin06 [liujiaxin06@linuxprobe test]$ id liujiaxin06 uid=1006(liujiaxin06) gid=1001(liujiaxin06) groups=1001(liujiaxin06) [liujiaxin06@linuxprobe test]$ echo "xxxxxx" >> file01 -bash: file01: Permission denied [liujiaxin06@linuxprobe test]$ echo "xxxxxx" >> file04 -bash: file04: Permission denied [liujiaxin06@linuxprobe test]$ echo "xxxxxx" >> file06 [liujiaxin06@linuxprobe test]$ echo "xxxxxx" >> file07 [liujiaxin06@linuxprobe test]$ echo "xxxxxx" >> file09

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。