首页 > 系统 > Linux > 正文

linux系统基本权限讲解

2020-10-14 22:38:07
字体:
来源:转载
供稿:网友

  Linux系统中的每一个文件都与多种权限类型相关联。在这些权限中,我们主要和三类权限打交 道:用户(user)、用户组(group)和其他用户(others)。用户是文件的所有者;用户组是指和文件所有者在同一组的其他多个用户的集合;其 他用户是除用户或用户组之外的任何用户。

  ls -l命令可以列出文件的权限,如:

  -rw-rw-r-- 1 lfqy lfqy  529  6月 11 20:21 file-authority.txt

  -rw-rw-r-- 1 lfqy lfqy    0  6月 11 19:02 helloworld

  drwxrwxr-x 2 lfqy lfqy 4096  6月 11 20:21 try

  可以看出,每一行输出代表一个文件。每行输出的前10个字符代表文件的权限信息:第一个字符代表文件的类型(-表示普通文件,d表示目录,c表 示字符设备,b表示块设备,l表示符号链接,s表示套接字,p表示管道),剩下的部分可以划分成三组(第一组的三个字符对应用户权限,第二组的三个字符对 应用户组权限,第三组的三个字符对应其他用户权限。这9个字符中的每一个字符指明是否设置了某种权限,如果设置了权限,对应位置上就会出现一个字符,否则 就一个'-'表明没有设置对应的权限)。其中r代表读权限,w代表写权限,x代表执行权限,比如第一行中的file-authority.txt文件属于 用户lfqy,该用户对其拥有读写权限,而没有执行权限,和lfqy在同一组的其他用户也拥有对该文件的读写权限,而其他用户对其只有读权限。

  1、文件的权限

  1.1 文件的基本权限

  rwx分别对应文件的读权限、写权限和可执行权限,然而,对于目录来说,这三种权限有不同的含义。目录的读权限允许读取目录中文件和子目录的列表,目录的写权限允许在目录中创建或删除文件或目录,目录的可执行权限指明是否可以访问目录中的文件和子目录。

  1.2 setuid、setgid和sticky bit

  实际上,除了最基本的读、写和执行权限之外,Linux中还有setuid、setgid和sticky bit等三种权限。下面分别解释这三种权限。

  关于setuid和setgid维基百科上的解释如下:

  setuid and setgid (short for "set user ID upon execution" and "set group ID upon execution", respectively) are Unix access rights flags that allow users to run an executable with the permissions of the executable's owner or group respectively and to change behaviour in directories. They are often used to allow users on a computer system to run programs with temporarily elevated privileges in order to perform a specific task.

  The setuid and setgid flags, when set on a directory, have an entirely different meaning.

  Setting the setgid permission on a directory (chmod g+s) causes new files and subdirectories created within it to inherit its group ID, rather than the primary group ID of the user who created the file (the owner ID is never affected, only the group ID). Newly created subdirectories inherit the setgid bit. Thus, this enables a shared workspace for a group without the inconvenience of requiring group members to explicitly change their current group before creating new files or directories. Note that setting the setgid permission on a directory only affects the group ID of new files and subdirectories created after the setgid bit is set, and is not applied to existing entities. Setting the setgid bit on existing subdirectories must be done manually, with a command such as the following:

  [root@foo]# find /path/to/directory -type d -exec chmod g+s {} /;

  The setuid permission set on a directory is ignored on UNIX and Linux systems. FreeBSD can be configured to interpret it analogously to setgid, namely, to force all files and sub-directories to be owned by the top directory owner.
(责任编辑:VEVB)

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表