linux

时间:2015-10-08 23:21:44

标签: linux

现在我正在研究linux的操作系统。

我的问题是“linux中目录和常规文件之间的权限有什么不同?”

由于

2 个答案:

答案 0 :(得分:1)

如果您在使用ls -l时谈论mod位,则目录通常设置d mod位,而常规文件没有。

例如,假设当前目录中有一个名为directory的目录和一个名为reg_file的常规文件。运行ls -l,您将获得

drwxrwxr-x 2 user group 4096 Oct  8 19:35 directory
-rw-rw-r-- 1 user group    0 Oct  8 19:35 reg_file

在这种情况下,第一行位模式中的前导d表示directory是文件夹。同样,第二行中的前导-表示reg_file是常规文件。

答案 1 :(得分:0)

虽然已经在基于Linux的系统中内置了许多良好的安全功能,但是在授予本地访问权限时可能存在一个非常重要的潜在漏洞 - 这是由于用户未分配正确权限而导致的基于文件权限的问题文件和目录。因此,基于对适当权限的需求,我将介绍分配权限的方法,并向您展示可能需要修改的一些示例。

基本文件权限

权限组

每个文件和目录都有三个基于用户的权限组:

**owner** - The Owner permissions apply only the owner of the file or directory, they will not impact the actions of other users.
**group** - The Group permissions apply only to the group that has been assigned to the file or directory, they will not effect the actions of other users.
**all users** - The All Users permissions apply to all other users on the system, this is the permission group that you want to watch the most.

权限类型

每个文件或目录都有三种基本权限类型:

read - The Read permission refers to a user's capability to read the contents of the file.
write - The Write permissions refer to a user's capability to write or modify a file or directory.
execute - The Execute permission affects a user's capability to execute a file or view the contents of a directory.

查看权限

您可以通过检查您喜欢的GUI文件管理器中的文件或目录权限(我在此不会介绍)或查看\" ls -l \"的输出来查看权限。在终端中以及在包含文件或文件夹的目录中工作时执行命令。

命令行中的权限显示为:_rwxrwxrwx 1 owner:group

User rights/Permissions
    The first character that I marked with an underscore is the special permission flag that can vary.
    The following set of three characters (rwx) is for the owner permissions.
    The second set of three characters (rwx) is for the Group permissions.
    The third set of three characters (rwx) is for the All Users permissions.
Following that grouping since the integer/number displays the number of hardlinks to the file.
The last piece is the Owner and Group assignment formatted as Owner:Group.

修改权限

在命令行中,使用命令chmod编辑权限。您可以显式分配权限,也可以使用二进制引用分配权限,如下所述。 明确定义权限

要明确定义权限,您需要引用权限组和权限类型。

使用的权限组是:

u - Owner
g - Group
o or a - All Users

潜在的分配操作符是+(加号)和 - (减号);这些用于告诉系统是否添加或删除特定权限。

使用的权限类型是:

r - Read
w - Write
x - Execute

举一个例子,假设我有一个名为file1的文件,该文件当前的权限设置为_rw_rw_rw,这意味着所有者,组和所有用户都具有读写权限。现在我们要删除所有用户组的读写权限。

要进行此修改,您将调用以下命令:chmod a-rw file1 要添加上述权限,您将调用以下命令:chmod a + rw file1

如您所见,如果您要授予这些权限,则可以将减号更改为加号以添加这些权限。 使用二进制引用设置权限

现在您已了解权限组和类型,这应该感觉很自然。要使用二进制引用设置权限,您必须首先通过输入三个整数/数字来理解输入。

示例权限字符串将是chmod 640 file1,这意味着所有者具有读取和写入权限,该组具有读取权限,而所有其他用户都没有该文件的权限。

第一个数字代表所有者权限;第二个代表组权限;最后一个数字代表所有其他用户的权限。这些数字是rwx字符串的二进制表示。

r = 4
w = 2
x = 1

您可以添加数字以获取表示您希望设置的权限的整数/数字。您需要为三个权限组中的每一个都包含二进制权限。

因此,要将文件设置为file1上的权限以读取_rwxr_____,您将输入chmod 740 file1。

所有者和团体

我已经对上面的所有者和群组进行了多次引用,但尚未告诉您如何分配或更改分配给文件或目录的所有者和组。

使用chown命令更改所有者和组分配,语法是简单的chown所有者:group filename,因此要将file1的所有者更改为user1,将组更改为family,您将输入chown user1:family file1。

高级权限

特殊权限标志可以使用以下任何一种标记:

_ - no special permissions
d - directory
l - The file or directory is a symbolic link
s - This indicated the setuid/setgid permissions. This is not set displayed in the special permission part of the permissions display, but is represented as a s in the read portion of the owner or group permissions.
t - This indicates the sticky bit permissions. This is not set displayed in the special permission part of the permissions display, but is represented as a t in the executable portion of the all users permissions

Setuid / Setgid特殊权限

setuid / setguid权限用于告诉系统以拥有者权限的身份运行可执行文件。

小心使用权限中的setuid / setgid位。如果您使用setuid / setgid位设置错误地将权限分配给root拥有的文件,则可以打开系统以进行入侵。

您只能通过显式定义权限来分配setuid / setgid位。 setuid / setguid位的字符是s。

所以在file2.sh上设置setuid / setguid位你会发出命令chmod g + s file2.sh。

粘性位特殊权限

粘性位在共享环境中非常有用,因为当它被分配给目录上的权限时,它会设置它,所以只有文件所有者才能重命名或删除所述文件。

您只能通过显式定义权限来分配粘滞位。粘滞位的字符是t。

要在名为dir1的目录上设置粘滞位,您将发出命令chmod + t dir1。 权限很重要时

对于基于Mac或Windows的计算机的某些用户,您不必考虑权限,但除非您在公司环境中,否则这些环境不会如此积极地关注基于用户的文件权限。但是现在您正在运行基于Linux的系统,并且基于权限的安全性得到了简化,并且可以轻松地用于限制访问。

因此,我将向您展示一些您想要关注的文档和文件夹,并向您展示如何设置最佳权限。

home directories - The users\' home directories are important because you do not want other users to be able to view and modify the files in another user\'s documents of desktop. To remedy this you will want the directory to have the drwx______ (700) permissions, so lets say we want to enforce the correct permissions on the user user1\'s home directory that can be done by issuing the command chmod 700 /home/user1.
bootloader configuration files - If you decide to implement password to boot specific operating systems then you will want to remove read and write permissions from the configuration file from all users but root. To do you can change the permissions of the file to 700.
system and daemon configuration files - It is very important to restrict rights to system and daemon configuration files to restrict users from editing the contents, it may not be advisable to restrict read permissions, but restricting write permissions is a must. In these cases it may be best to modify the rights to 644.
firewall scripts - It may not always be necessary to block all users from reading the firewall file, but it is advisable to restrict the users from writing to the file. In this case the firewall script is run by the root user automatically on boot, so all other users need no rights, so you can assign the 700 permissions.

可以给出其他示例,但本文已经非常冗长,因此如果您想分享其他所需限制的示例,请在评论中这样做。 评论欢迎

如果您有任何要添加或想要发表评论或更正的内容,请在评论中注明。我期待着您的反馈,并希望您在未来使用基于Linux的系统时做到最好。

进一步参考检查此http://linuxcommand.org/