红联Linux门户
Linux帮助

Linux下的两个特殊文件权限

发布时间:2007-10-29 11:38:40来源:红联作者:rmidable
今天遇到两个特殊的文件权限:

1,SUID和SGID属性
有时,没有被授权的用户需要完成某项任务。一个例子是passwd程序,它允许用户改变口令,这就要求改变/etc/passwd文件的口令域。然而系统管理员决不允许普通用户拥有直接改变这个文件的权利,因为这绝对不是一个好主意。 为了解决这个问题,SUID/SGID便应运而生。

chmod 4xxx 是设置SUID属性,chmod 2xxx是设置SGID属性。chmod 1xxx是设置(restricted deletion flag or sticky bit)位。

设置SUID或SGID后,文件执行时将以所设置的“身份”来运行。例如,如果用户A对文件file设置了SUID,那么当用户B执行文件file时,将以用户A的身份来运行,也就是说在执行file时将拥有跟A一样的权限。所以对于上面提到的password问题,我们可以这样解决:

(以root身份运行)
#chmod 4511 passwd

这样,当普通用户执行passwd命令时,passwd命令就可以以root的身份成功地修改/etc/passwd文件

2,restricted deletion flag or sticky bit
The restricted deletion flag or sticky bit is a single bit, whose interpretation depends on the file type. For directories, it prevents unprivileged users from removing or renaming a file in the directory unless they own the file or the directory; this is called the restricted deletion flag for the directory, and is commonly found on world-writable directories like /tmp. For regular files on some older systems, the bit saves the program’s text image on the swap device so it will load more quickly when run; this is called the sticky bit.
文章评论

共有 0 条评论