如何删除 setgid (linux/unix)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14529325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 18:48:28  来源:igfitidea点击:

How to remove setgid (linux/unix)?

linuxunix

提问by bigpotato

I just changed my file permissions using $ sudo chmod g+s filenameand my file permissions turned from drwxr-xr-xto drwxr-sr-x. How do I remove it?

我只是用改变了我的文件权限$ sudo chmod g+s filename和把我的文件权限drwxr-xr-xdrwxr-sr-x。如何删除它?

采纳答案by andrewdotn

Change the +for adding a permission into a -to remove it:

+添加权限更改为-删除权限:

sudo chmod g-s filename

回答by DJAdmin

To remove setgid the numerical way the command is

要删除 setgid 命令的数字方式

sudo chmod 0664 $filename

须藤chmod 0664 $文件名

The assumption here is the permission on file is 664 and we are not changing it. The left most bit in the above command represents setuid(4),setgid(2) and sticky(1). Now to represent these symbolically setuid is u+s, setgid is g+sand sticky is o+t

这里的假设是文件的权限是 664,我们不会改变它。上述命令中最左边的位代表 setuid( 4)、setgid( 2) 和 sticky( 1)。现在象征性地表示这些 setuid 是u+s, setgid 是g+s,sticky 是o+t

Example 1:-chmod u+s filename This will setuid for the filename mentioned that is rwsr_xr_x

示例 1:-chmod u+s filename 这将为提到的文件名设置uid rw sr_xr_x

Example 2: chmod 2770 directory This will set gid for the directory mentioned that is rwxr_sr_x

示例 2:chmod 2770 目录 这将为提到的目录设置 gid,即 rwxr_ sr_x

回答by Tom Ratcliff

Regarding: "you can set (but not clear) the bits with a numeric mode"

关于:“您可以使用数字模式设置(但不清除)位”

On RHEL 7 chmod 0644 $filename did not remove the setuid(4),setgid(2) or sticky(1).

在 RHEL 7 上,chmod 0644 $filename 没有删除 setuid(4)、setgid(2) 或 sticky(1)。

However precedeing with an extra 0 did the trick:

然而,在额外的 0 之前有诀窍:

chmod 00644 $filename

chmod 00644 $filename

回答by Jagadish Sahoo

Well would just like to add few points to clarify the approach of working with the numerical way for both files and directories.

好吧,我想补充几点来阐明使用数字方式处理文件和目录的方法。

  • Adding individual special permissions for either user/group/others.
  • 为用户/组/其他人添加单独的特殊权限。

chmod "X"755 file

chmod "X"755 file

Where X is the specific octal numeric mode for special permissions.

其中 X 是特殊权限的特定八进制数字模式。

  • If you want to add multiple special permissions at a time, e.g. for both suid(4) and sgid(2) i.e. 4+2=6.
  • 如果您想一次添加多个特殊权限,例如 suid(4) 和 sgid(2) 即 4+2= 6

chmod "6"755 file

chmod "6"755 file

for suid(4), sgid(2) and sticky bit(1), i.e. 4+2+1=7

对于 suid(4)、sgid(2) 和粘滞位 (1),即 4+2+1= 7

chmod "7"755 file

chmod "7"755 file

  • Deleting all special permissions (only applicable for a file)
  • 删除所有特殊权限(仅适用于文件)

chmod 00"0"755 file

chmod 00"0"755 file

Well, the trailing zeros before 4 digits doesn't add any values while changing the permission for a file but it does add values while changing permission for a directory.

The above numeric code will change the permission to 755 from 7755 only for a file but if you do the same for a directory it will be 6755 as it will only remove the sticky bit for others.

To remove all the special permissions for a directory.

chmod "000"755 file

好吧,4 位数字之前的尾随零在更改文件权限时不会添加任何值,但会在更改目录权限时添加值。

上面的数字代码将仅针对文件将权限从 7755 更改为 755,但如果您对目录执行相同操作,它将是 6755,因为它只会删除其他人的粘滞位。

删除目录的所有特殊权限。

chmod "000"755 file

  • Similarly, to remove suid permission and having sgid(2) and sticky bit(1) i.e. 2+1=3.
  • 类似地,删除 suid 权限并具有 sgid(2) 和 sticky bit(1) 即 2+1= 3

chmod 00"3"755 file

chmod 00"3"755 file

And solution using letters(r,w,x,X,s,,t) and operators(+/-) were already discussed and approved in the earlier answers.

使用字母 (r,w,x,X,s,,t) 和运算符 (+/-) 的解决方案已在早期答案中讨论和批准。