Linux培训笔记之Linux权限详解

Linux培训笔记之Linux权限详解

--------------------------------------分割线 --------------------------------------

Linux用户权限学习笔记

Linux 用户管理常用命令

Linux用户、组的管理常用到的命令介绍

Linux_用户、组和权限问题

Linux 的用户和组命令

Linux的用户与权限管理

--------------------------------------分割线 --------------------------------------

一、special permissions for executables
1.special permissions for executables:
  -suid:command run with permissions of the owner of the command,not executor of  the command
  -sgid:command runs with group affiliation of the group of the command
eg:
file:
user    group    other
suid    sgid

二、special permissions for direct
1.sgid is used to create a collaborative directory
  -when a file is created in a directory with the SGID bit set,it belongs to the same group as the directory,rather than the creator's primary gropu
  -#chmod g+s directory  (让该文件夹带上SGID权限,可以转换为组身份)
  -#chmod u+s directory  (让该文件夹带上SUID权限,可以转换为用户身份)
2.sticky allows only the owner of a file to delete it
  -normally user with write permission to a directory can delete any file in that directotry regardless of that file's permission or ownership
  -#chmod o+t directory  (例如 /tmp/目录)
eg:
[root@instructor ~]# ll -d /tmp
drwxrwxrwt. 18 root root 12288 Jan  2 19:51 /tmp
[root@instructor ~]#
dir:
user    group    other
        sticky

实验一:新建一个CORP文件夹,分配给IT组,组内有三个成员frodo,sam,pippin。三个用户都可以创建自己的文件,并且其他组内成员都可以看,可以修改。
[root@instructor ~]# mkdir /corp
[root@instructor ~]# chmod 770 /corp  (权限为rwxrwx---)
[root@instructor ~]# groupadd IT
[root@instructor ~]# chgrp IT /corp  (将/corp分配给IT组)
[root@instructor ~]# ll -d /corp
drwxrwx---. 2 root IT 4096 Jan  2 21:37 /corp
[root@instructor ~]# chmod 777 /corp
[root@instructor ~]# ll -d /corp
drwxrwxrwx. 2 root IT 4096 Jan  2 21:37 /corp
[root@instructor ~]# vi /etc/group    (进入/etc/group将frodo,sam,pippin三个用户添加进IT组)

IT:x:502:sam,pippin,frodo
"/etc/group" 72L, 1012C written
[root@instructor ~]# ll -d /corp
drwxrwxrwx. 2 root IT 4096 Jan  2 21:37 /corp
[root@instructor ~]# chmod 770 /corp
[root@instructor ~]# ll -d /corp
drwxrwx---. 2 root IT 4096 Jan  2 21:37 /corp
[root@instructor ~]# su - frodo
[frodo@instructor ~]$ id
uid=506(frodo) gid=507(frodo) groups=507(frodo),502(IT) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[frodo@instructor ~]$ cd /corp
[frodo@instructor corp]$ ll -d
drwxrwx---. 2 root IT 4096 Jan  2 21:37 .
[frodo@instructor corp]$ touch frodofile (创建一个名为frodofile的文件)
[frodo@instructor corp]$ ll
total 0
-rw-rw-r--. 1 frodo frodo 0 Jan  2 21:46 frodofile  (文件权限为rw-rw-r,664)
[frodo@instructor corp]$ su -
Password:
[root@instructor ~]# su - sam
[sam@instructor ~]$ cd /corp
[sam@instructor corp]$ ll
total 0
-rw-rw-r--. 1 frodo frodo 0 Jan  2 21:46 frodofile
[sam@instructor corp]$ touch samfile  (创建一个名为samfile的文件)
[sam@instructor corp]$ ll
total 0
-rw-rw-r--. 1 frodo frodo 0 Jan  2 21:46 frodofile
-rw-rw-r--. 1 sam  sam  0 Jan  2 21:47 samfile
[sam@instructor corp]$ su -
Password:
[root@instructor ~]# su - pippin
[pippin@instructor ~]$ cd /corp
[pippin@instructor corp]$ ll
total 0
-rw-rw-r--. 1 frodo frodo 0 Jan  2 21:46 frodofile
-rw-rw-r--. 1 sam  sam  0 Jan  2 21:47 samfile

[pippin@instructor corp]$ touch pippinfile  (创建一个名为pippinfile的文件)
[pippin@instructor corp]$ ll
total 0
-rw-rw-r--. 1 frodo  frodo  0 Jan  2 21:46 frodofile
-rw-rw-r--. 1 pippin pippin 0 Jan  2 21:48 pippinfile
-rw-rw-r--. 1 sam    sam    0 Jan  2 21:47 samfile
[pippin@instructor corp]$ su - frodo
Password:
[frodo@instructor ~]$ ll
total 0
[frodo@instructor ~]$ ll -d /corp
drwxrwx---. 2 root IT 4096 Jan  2 21:48 /corp
[frodo@instructor ~]$ cd /corp
[frodo@instructor corp]$ ll
total 0
-rw-rw-r--. 1 frodo  frodo  0 Jan  2 21:46 frodofile  (注意这里的组别为frodo)
-rw-rw-r--. 1 pippin pippin 0 Jan  2 21:48 pippinfile (注意这里的组别为pippin)
-rw-rw-r--. 1 sam    sam    0 Jan  2 21:47 samfile    (注意这里的组别为sam)
[frodo@instructor corp]$ vim samfile
~
~
(frodo既不是sam用户,又不是sam组成员,只是others,而others只有可读权限,所以frodo无法修改sam的文件,我们需要用户自己创建的文件属于自己,但是组别统一属于IT组,这里明显不符合要求,删除文件,重来)
[frodo@instructor corp]$
[frodo@instructor corp]$ ll
total 0
-rw-rw-r--. 1 frodo  frodo  0 Jan  2 21:46 frodofile
-rw-rw-r--. 1 pippin pippin 0 Jan  2 21:48 pippinfile
-rw-rw-r--. 1 sam    sam    0 Jan  2 21:47 samfile
[frodo@instructor corp]$ su -
Password:
[root@instructor ~]#
[root@instructor ~]# cd /corp
[root@instructor corp]# ll
total 0
-rw-rw-r--. 1 frodo  frodo  0 Jan  2 21:46 frodofile
-rw-rw-r--. 1 pippin pippin 0 Jan  2 21:48 pippinfile
-rw-rw-r--. 1 sam    sam    0 Jan  2 21:47 samfile
[root@instructor corp]# rm * -f
[root@instructor corp]# ll
total 0
[root@instructor corp]# cd ..
[root@instructor /]# ll -d /corp
drwxrwx---. 2 root IT 4096 Jan  2 21:57 /corp
[root@instructor /]# chmod g+s corp/  (注意这里给文件夹的组属性添加SGID属性)
[root@instructor /]# ll -d corp/
drwxrws---. 2 root IT 4096 Jan  2 21:57 corp/
[root@instructor /]# su - frodo
[frodo@instructor ~]$ cd /corp/
[frodo@instructor corp]$ ll
total 0
[frodo@instructor corp]$ touch frodofile
[frodo@instructor corp]$ ll
total 0
-rw-rw-r--. 1 frodo IT 0 Jan  2 22:00 frodofile  (注意这里frodo创建的文件组别属于IT组了)
[frodo@instructor corp]$ su - sam
Password:
[sam@instructor ~]$ cd /corp
[sam@instructor corp]$ ll
total 0
-rw-rw-r--. 1 frodo IT 0 Jan  2 22:00 frodofile
[sam@instructor corp]$ touch samfile
[sam@instructor corp]$ ll
total 0
-rw-rw-r--. 1 frodo IT 0 Jan  2 22:00 frodofile
-rw-rw-r--. 1 sam  IT 0 Jan  2 22:01 samfile  (注意这里sam创建的文件组别属于IT组了)
[sam@instructor corp]$ su - pippin
Password:
[pippin@instructor ~]$ cd /corp
[pippin@instructor corp]$ touch pippinfile
[pippin@instructor corp]$ ll
total 0
-rw-rw-r--. 1 frodo  IT 0 Jan  2 22:00 frodofile
-rw-rw-r--. 1 pippin IT 0 Jan  2 22:01 pippinfile  (注意这里pippin创建的文件组别属于IT组了)
-rw-rw-r--. 1 sam    IT 0 Jan  2 22:01 samfile
[pippin@instructor corp]$ su - frodo
Password:
[frodo@instructor ~]$ cd /corp
[frodo@instructor corp]$ ll
total 0
-rw-rw-r--. 1 frodo  IT 0 Jan  2 22:00 frodofile  (都属于IT组)
-rw-rw-r--. 1 pippin IT 0 Jan  2 22:01 pippinfile (都属于IT组)
-rw-rw-r--. 1 sam    IT 0 Jan  2 22:01 samfile    (都属于IT组)
[frodo@instructor corp]$ vim samfile
~
~

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/17904.html