文件、文件夹的用户管理权限(2)
特殊权限位
Linux系统提供的一个有12个权限位
默认的 属主 rwx
属组 rwx
其他用户 rwx
这就是9个权限了
还有三个隐藏权限
suid chmod u+s 当属主没有x权限 会变成大写S 有x权限 是小写s
suid把文件变成公共的,大家都是主人,可以享有和主人一样的权力,想干什么干什么
sgid chmod g+s 当属组没有x权限 会变成大写S 有x权限 是小写s
sgid 把文件夹的组设置成了共享组,普通用户在这个文件夹里创建的文件和文件夹都会自动属于该共享组,并且享有这个组的权限
sticky chmod o+t 其他用户没有x权限 会变成大写T 有x权限 是小写t
sticky(黏着位) 给文件夹设置沾滞位权限,让用户之间不能对他人的文件随意的删除
chmod u+s 增加文件属主的suid权限
chmod u-s 取消你文件属主的suid权限
chmod g+s 增加文件属组的sgid权限
chmod g-s 去掉你文件属组的sgid权限
chmod o-t 增加文件的粘滞位
chmod o+t 取消文件的粘滞位

suid演示
有s权限 用户可以自己修改密码
[root@localhost ~17:02:16]# ll /usr/bin/passwd
-rwsr-xr-x. 1 root root 27856 Apr 1 2020 /usr/bin/passwd
[root@localhost ~17:03:09]#
[jack01@localhost ~17:07:01]$ passwd
Changing password for user jack01.
Changing password for jack01.
(current) UNIX password:
New password:
BAD PASSWORD: The password is a palindrome
New password:
BAD PASSWORD: The password is a palindrome
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[jack01@localhost ~17:07:30]$
没有s权限,用户不能修改密码
[root@localhost ~17:03:09]# chmod u-s /usr/bin/passwd
[root@localhost ~17:08:42]# ll /usr/bin/passwd
-rwxr-xr-x. 1 root root 27856 Apr 1 2020 /usr/bin/passwd
[root@localhost ~17:08:48]#
[jack01@localhost ~17:07:30]$ passwd
Changing password for user jack01.
Changing password for jack01.
(current) UNIX password:
New password:
Retype new password:
passwd: Authentication token manipulation error
[jack01@localhost ~17:09:50]$
sgid演示
创建文件夹77
创建组 afei
将77文件夹的组改为afei
[root@localhost /opt17:24:44]# mkdir 77
[root@localhost /opt17:24:54]# ll
total 0
drwxr-xr-x. 2 root root 6 Mar 17 17:24 77
[root@localhost /opt17:24:56]# chmod 770 77
[root@localhost /opt17:25:19]# ll
total 0
drwxrwx---. 2 root root 6 Mar 17 17:24 77
[root@localhost /opt17:25:21]# groupadd 666
groupadd: '666' is not a valid group name
[root@localhost /opt17:26:31]# groupadd afei
[root@localhost /opt17:26:38]# chgrp afei /opt/77
[root@localhost /opt17:26:57]# ll
total 0
drwxrwx---. 2 root afei 6 Mar 17 17:24 77
[root@localhost /opt17:26:59]#
还没改77的文件夹组共享的
[root@localhost /opt/7717:27:26]# mkdir 66
[root@localhost /opt/7717:27:36]# ll
total 0
drwxr-xr-x. 2 root root 6 Mar 17 17:27 66
[root@localhost /opt/7717:27:37]#
将77文件夹属组共享
[root@localhost /opt/7717:27:37]# chmod g+s /opt/77
[root@localhost /opt/7717:28:25]# ll /opt
total 0
drwxrws---. 3 root afei 16 Mar 17 17:27 77
然后创建了88.txt文件和33文件夹
发现都属于同一个组
[root@localhost /opt/7717:28:38]#
[root@localhost /opt/7717:28:38]# touch 88.txt
[root@localhost /opt/7717:29:12]# mkdir 33
[root@localhost /opt/7717:29:19]# ll
total 0
drwxr-sr-x. 2 root afei 6 Mar 17 17:29 33
drwxr-xr-x. 2 root root 6 Mar 17 17:27 66
-rw-r--r--. 1 root afei 0 Mar 17 17:29 88.txt
[root@localhost /opt/7717:29:22]#
sbit命令
1、创建目录
[root@localhost /opt17:32:56]# mkdir 999
[root@localhost /opt17:33:09]# ll
total 0
drwxr-xr-x. 2 root root 6 Mar 17 17:33 999
[root@localhost /opt17:33:13]#
[root@localhost /opt17:35:52]# chmod o+w 999
[root@localhost /opt17:36:21]# ll
total 0
drwxr-xrwx. 2 root root 6 Mar 17 17:33 999
[root@localhost /opt17:36:22]#
2、分别用两个用户进入创建文件
[jack01@localhost /opt/99917:35:23]$ touch 111.txt
[afei01@localhost /opt/999]$ touch 222.txt
[afei01@localhost /opt/999]$ ll
total 0
-rw-rw-r--. 1 jack01 jack01 0 Mar 17 17:36 111.txt
-rw-rw-r--. 1 afei01 afei01 0 Mar 17 17:38 222.txt
[afei01@localhost /opt/999]$
3、删除
[afei01@localhost /opt/999]$ rm -rf ./111.txt
[afei01@localhost /opt/999]$ ll
total 0
-rw-rw-r--. 1 afei01 afei01 0 Mar 17 17:38 222.txt
[afei01@localhost /opt/999]$
4、给目录加粘滞位
[root@localhost /opt17:36:22]# chmod o+t 999
[root@localhost /opt17:40:41]# ll
total 0
drwxr-xrwt. 2 root root 21 Mar 17 17:39 999
[root@localhost /opt17:40:42]#
5、再次删除验证
[jack01@localhost /opt/99917:36:38]$ ll
total 0
-rw-rw-r--. 1 afei01 afei01 0 Mar 17 17:38 222.txt
[jack01@localhost /opt/99917:41:18]$ rm -rf ./222.txt
rm: cannot remove ‘./222.txt’: Operation not permitted
[jack01@localhost /opt/99917:41:36]$
umask命令
umask 命令用来设置限制新文件权限的掩码。当新文件被创建时,其最初的权限由文件创建掩码决定。用户每次注册进入系统时,umask命令都被执行,并自动设置掩码改变默认值,新的权限将会把旧的覆盖。
参数
-S大写的 以字符的形式显示当前的掩码
-p 带umask开头以数字的形式显示当前掩码