[My Linux, I call the shots! Detailed rights management] Linux

(1) understand the concept and modify the file owner belongs to the group of
assumptions Tom now has a kindle in use, he said later bought: "I not only use all the students in our class can also find me if you need to use, but in addition to others outside our class can not be used. " In this class owner kindle the user is Tom, the kindle is a group where the group is Tom, other people can not use the other kindle. Therefore, set permissions for the file, that is, the corresponding u, g, o relevant settings.
[My Linux, I call the shots!  Detailed rights management] Linux
Meaning of the file attribute information as follows (FIG. 1-2):
[My Linux, I call the shots!  Detailed rights management] Linux
Modify the owner and group information file aa.txt genus (FIG. 1-3):
# chown root.users aa.txt
# chown .jerry aa.txt
[My Linux, I call the shots!  Detailed rights management] Linux
directory changes owner information and owner information does not change the internal file directory (FIG. 1-4):
# chown Jerry Books /
[My Linux, I call the shots!  Detailed rights management] Linux
If you need to modify the directory is a group of the owner and also can be changed when a file directory, the owner and group information, can add -R options:
# chown -R Jerry Books /
If you want to change information alone belonging group can be used chgrp (FIG. 1-5):
[My Linux, I call the shots!  Detailed rights management] Linux


(2)了解用户权限及修改权限
[My Linux, I call the shots!  Detailed rights management] Linux
其中第一个表示的是文件类型(图1-6):
【d】表示的是目录;
【-】表示的是普通文件,文本文件,二进制文件;
【l】表示的是软链接,快捷方式;
【b】表示设备文件,块文件,装置文件里面的可供存储的接口设备
【c】表示的是设备文件,字符文件,装置里面的串行端口设备,不可以存储东西,例如键盘,鼠标。
[My Linux, I call the shots!  Detailed rights management] Linux
九个字符的位置表示权限(图1-7):
r:可读(用数字4表示)
w:可写(用数字2表示)
x:可执行(用数字1表示)
------文件:运行这个文件的时候,是否有权限运行这个文件里的命令
------目录:在系统中是否有权限(cd)进入到目录中
所以在图1-7中:
u=r+w+x------->7=4+2+1
g=r+(-)+x------>5=4+0+1
o=r+(-)+(-)---->4=4+0+0
如果文件的权限不符合我们的要求,我们可以使用chmod修改文件的权限(图1-8):
[My Linux, I call the shots!  Detailed rights management] Linux


(3)了解默认权限
我们创建了文件和目录,其中aa、bb、cc三个文件的权限为644,其中11、22、33三个目录的权限为755。(图1-9)
[My Linux, I call the shots!  Detailed rights management] Linux
而系统默认的遮罩码umask为:0022,其中最后三位有用,系统默认创建的文件权限为:666,系统默认创建的目录权限为:777。似乎可以理解为当前系统文件权限是666-022的结果得到644,当前系统目录的权限是777-022得到的结果是755。
[My Linux, I call the shots!  Detailed rights management] Linux
现在我们将遮罩码umask值设置为:0033,发现之前的理解并不完全正确,当前系统的目录权限是777-033得到的结果是744,但是当前系统文件的权限并不是666-033得到633,而实际为644。是由于计算目录的权限前需要将umask里所有的奇数减1。(如图1-11和图1-12)
[My Linux, I call the shots!  Detailed rights management] Linux
[My Linux, I call the shots!  Detailed rights management] Linux
现在反过来看,我们求umask的数值,如果创建文件的时候默认的权限为444,请问umask应该设置为多少?
[My Linux, I call the shots!  Detailed rights management] Linux


(4)了解一些特殊权限
(4.1)首先大家有没有思考过这样的问题,就是一个普通用户user为何能通过passwd修改自己的用户密码,而我们知道用户密码都是加密后存放在/etc/shadow中的,查看一下该文件的权限,如下:
[My Linux, I call the shots!  Detailed rights management] Linux
发现该文件中的user作为other用户不可能修改文件的内容,但是为什么user能够修改自己密码并且存入/etc/shadow中呢?
[My Linux, I call the shots!  Detailed rights management] Linux
首先是suid,特殊权限表示为s,作用在可执行文件的文件所有者owner上面,该权限表示任何拥有该文件权限的人,在执行的过程时都临时拥有该文件属主的权限。因为在文件所有者中有特殊权限s,所以在普通用户修改自己密码时,是通过临时获取了root的权限,然后才能修改密码并且存入到/etc/shadow中。
[My Linux, I call the shots!  Detailed rights management] Linux
接下来我们通过一个简单的例子来更好的说明这个特殊权限的功能
[My Linux, I call the shots!  Detailed rights management] Linux
[My Linux, I call the shots!  Detailed rights management] Linux
[My Linux, I call the shots!  Detailed rights management] Linux
然后我们将vim命令的属主加上s位。
[My Linux, I call the shots!  Detailed rights management] Linux
[My Linux, I call the shots!  Detailed rights management] Linux
[My Linux, I call the shots!  Detailed rights management] Linux
(4.2)对于sgid,特殊权限表示为s,在这里分为两种情况:
①当对一个可执行的二进制文件作用了SGID权限之后,任何拥有执行该文件权限的人,在执行的过程时都临时拥有该文件所属组的权限。
②当对一个目录作用了SGID权限之后,任何对该目录有wx权限的用户在该目录下创建的文件及目录的所有属均为目录的所有组。
假设存在一个目录/rh124,这个目录所属组为users,如果/rh124所属组的权限里有s位的话,那么不管是谁在这个目录里创建的文件或者目录,都将继承rh124所属组。
[My Linux, I call the shots!  Detailed rights management] Linux
[My Linux, I call the shots!  Detailed rights management] Linux
[My Linux, I call the shots!  Detailed rights management] Linux
(4.3)对于sticKy,特殊权限表示为t,它的功能为当对一个目录作用了sticKy之后(只限制组用户,目录的owner不受影响),该目录下的文件仅其所属者才能删除。
用于目录other的位置,意味着这个目录里的东西,除了所有者和root之外,其他用户时没有权限删除的,即使权限是777也不行。
使用root用户创建一个目录名为11,设置目录的可执行权限为777,设置目录11的属主和属组为tom。
[My Linux, I call the shots!  Detailed rights management] Linux
接着切换到tom用户,在11目录下创建test1文件,并设置test1文件的权限为777。
[My Linux, I call the shots!  Detailed rights management] Linux
测试发现jerry用户是可以直接删除tom用户创建的test1文件的。
[My Linux, I call the shots!  Detailed rights management] Linux
接着使用root用户给目录11的other位置加上t位,此时发现jerry用户无法删除tom用户创建的test1文件了。
[My Linux, I call the shots!  Detailed rights management] Linux
[My Linux, I call the shots!  Detailed rights management] Linux
(4.4)有时候我们看到设置文件权限的时候会有4个数字,其中第一个数字代表的就是suid,sgid,sticKy相关权限的组合(如图4-18和图4-19):
[My Linux, I call the shots!  Detailed rights management] Linux
[My Linux, I call the shots!  Detailed rights management] Linux
(4.5)文件的隐藏属性
文件的隐藏属性对于系统的安全有很大的帮助,尤其是在系统安全(Security)上面,不过要先强调的是,底下的chattr指令只能在Ext2/Ext3/Ext4的Linux传统文件系统上面完整生效,其他的文件系统可能就无法完整的支持这个指令了,例如xfs仅支持部分参数而已。
chattr(配置文件隐藏属性图4-20和图4-22)
chattr [+-=] [ASacdistu] 文件或目录名称
选项与参数:
+:增加某一个参数,其他原本不存在的参数则不动。
-:移除某一个特殊参数,其他原本不存在的参数则不动。
=:设定一定且仅有后面接的参数
A: When this attribute set A, if you have access to this file or directory, his access time atime will not be modified. Avoid I / O access slower machines over the disk.
S: general asynchronous file is written to disk, plus S if this attribute when you modify any file, which is written to disk synchronization modifiers in
a: After setting a, this document will only increase data, but can not modify the data can not be deleted, only root can set this property.
c: After setting this property will automatically compress the file will automatically decompress when read, but when the store will first be compressed before storage.
d: when the dump program is executed, setting the d attribute file or directory that can not be backed up dump.
i: The i may powerful, he can make a file can not be deleted, renamed, set the connection can not be written into the new data, for the security of the system has a great help, only root can set this property.
s: When a file set s property, if this file is deleted, he will be completely remove the hard disk space, so if mistakenly deleted, it is completely unable to save back.
u: s the contrary, when u use to configure file, if the file is deleted, the data content actually still exist on disk, you can save the file.
Note: The properties set common is a set value of i, and many value must be set as the root to set
[My Linux, I call the shots!  Detailed rights management] Linux
[My Linux, I call the shots!  Detailed rights management] Linux
lsattr (show hidden file attributes Figure 4-21 and 4-23)
the lsattr [-ADR] file or directory name
options and parameters:
-a: the property hidden files are also displayed.
-d: If you pick a directory, list only the file name in the directory rather than the property itself directory.
-R: also together with a parallel data subdirectory out.
[My Linux, I call the shots!  Detailed rights management] Linux
[My Linux, I call the shots!  Detailed rights management] Linux

Guess you like

Origin blog.51cto.com/13613726/2434516