Skip to content

Ss in SetUID、SetGID and Tt in Sticky bit

功能

  1. SetUID: 让执行该命令的用户以该命令拥有者的权限去执行
  2. SetGID: 让执行该命令的用户在执行程序的时候,组身份提升为该程序文件的属组
  3. Sticky bit/粘滞位: 除了该文件的创建者和root用户可以删除和修改,其他用户不能修改

举例

SetUID举例:/usr/bin/passwd

ll /usr/bin/passwd

-rwsr-xr-x 1 root root 33K Apr  6  2020 /usr/bin/passwd

SetGID举例:/usr/bin/crontab

ls -ahl /usr/bin/crontab

-rwxr-sr-x 1 root crontab 43K Oct 11  2019 /usr/bin/crontab

Sticky举例:/tmp

ll -d /tmp

drwxrwxrwt. 10 root root 4.0K Feb 13 21:00 /tmp

设置特殊权限

chmod u+s xxx # 设置setuid权限 
chmod g+s xxx # 设置setgid权限 
chmod o+t xxx # 设置stick bit权限,针对目录 
chmod 4775 xxx # 设置setuid权限 
chmod 2775 xxx # 设置setgid权限 
chmod 1775 xxx # 设置stick bit权限,针对目录 

大小写含义

  • 大写:原文件/目录没有执行(x)权限,通常这样设置是不生效的
  • 小写:原文件/目录有执行(x)权限

例如:

原文件:-rwxr-xr-x

增加SetUID后 4755

变为:-rwsr-xr-x

再如:

原文件:-rwxr--r--

增加SetGID后 2744

变为:-rwxr-Sr--

Sticky bit同理。

Disclaimer
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback me#imzye.me, replace # with @
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Try iOS App