[root@xue ~]# useradd tony
[root@xue ~]# mkdir /test
[root@xue ~]# ls /test/ -ld
drwxr-xr-x. 2 root root 6 Dec 15 02:39 /test/
[root@xue ~]# echo "123" > /test/test.txt
[root@xue ~]# ll /test/test.txt
-rw-r--r--. 1 root root 4 Dec 15 02:39 /test/test.txt
[root@xue ~]# su - tony
[tony@xue ~]$ cat /test/test.txt
123
删除其他用户的读取权限后,测试其他用户(tony)是否对/test/test.txt有读取权限。
[root@xue tony]# su -
Last login: Sat Dec 15 02:41:35 EST 2018 on pts/0
[root@xue ~]# chmod 640 /test/test.txt
[root@xue ~]# ll /test/test.txt
-rw-r-----. 1 root root 4 Dec 15 02:39 /test/test.txt
[root@xue ~]# su - tony
Last login: Sat Dec 15 02:40:32 EST 2018 on pts/0
[tony@xue ~]$ cat /test/test.txt
cat: /test/test.txt: Permission denied
删除其他用户对/test目录的读取权限,测试是否能够使用ls命令列出目录中的内容。
[tony@xue ~]$ su -
Password:
Last login: Sat Dec 15 02:41:46 EST 2018 on pts/0
[root@xue ~]# ls /test/ -ld
drwxr-xr-x. 2 root root 21 Dec 15 02:39 /test/
[root@xue ~]# chmod 751 /test/
[root@xue ~]# ll -d /test/
drwxr-x--x. 2 root root 21 Dec 15 02:39 /test/
创建tonyGroup组,将/test/test.txt的属组修改为tonyGroup。将tony用户加入tonyGroup而不使tony离开原来的tony组。
[root@xue ~]# groupadd tonyGroup
[root@xue ~]# grep tonyGroup /etc/group
tonyGroup:x:1001:
tonyGroup01:x:1002:tony01
tonyGroup3:x:1005:tony03
[root@xue ~]# usermod -a -G tonyGroup tony
[root@xue ~]# grep tonyGroup /etc/group
tonyGroup:x:1001:tony
tonyGroup01:x:1002:tony01
tonyGroup3:x:1005:tony03
[root@xue ~]# ls -l /test/test.txt
-rw-r-----. 1 root root 4 Dec 15 02:39 /test/test.txt
[root@xue ~]# chown :tonyGroup /test/test.txt
[root@xue ~]# ls -l /test/test.txt
-rw-r-----. 1 root tonyGroup 4 Dec 15 02:39 /test/test.txt
设置/test/test.txt的权限为600,使用tony用户查看文件内容。
[root@xue ~]# chmod 600 /test/test.txt
[root@xue ~]# ll /test/test.txt
-rw-------. 1 root tonyGroup 4 Dec 15 02:39 /test/test.txt
[root@xue ~]# su - tony
Last login: Sat Dec 15 02:42:22 EST 2018 on pts/0
[tony@xue ~]$ cat /test/test.txt
cat: /test/test.txt: Permission denied
[tony@xue ~]$ su -
Password:
Last login: Sat Dec 15 02:43:26 EST 2018 on pts/0
设置/test/test.txt的权限为640,使用tony用户查看文件内容。
[root@xue ~]# chmod 640 /test/test.txt
[root@xue ~]# ll /test/test.txt
-rw-r-----. 1 root tonyGroup 4 Dec 15 02:39 /test/test.txt
[root@xue ~]# su - tony
Last login: Sat Dec 15 02:48:58 EST 2018 on pts/0
[tony@xue ~]$ cat /test/test.txt
123
网友评论