8, linux rights - special rights

Special Permissions:

1.setuid

setuid: let ordinary users to have the owner's permission to temporarily command to complete some special operations.

suid的授权:
    chmod u+s   
    chmod u-s
    chmod 4755 4代表是特殊权限suid,755代表文件原本的属主属组以及其他人的权限
注意:不要随便使用suid,知道就行.

2.setgid

setgid作业,创建三个用户, 分别为`curly``larry``moe`这些用户都是`stooges`组的成员。
这些用户帐号密码都为`password`
1.要求以上用户和组可以在`/home/stooges`目录里访问,创建,删除文件
2.其他用户一律不允许访问该目录
3.在该目录下新建的文件会自动属于`stooges`组拥有

//创建用户,组
useradd curly
useradd larry
useradd moe
groupadd stooges

//创建密码
echo "password" |passwd --stdin moe
echo "password" |passwd --stdin larry
echo "password" |passwd --stdin curry

//将用户加组
gpasswd -a larry stooges
gpasswd -a moe stooges
gpasswd -a curly stooges

//创建目录并配置权限
mkdir /home/stooges
chmod 770 /home/stooges
chown .stooges /home/stooges
chmod g+s /home/stooges

sgid role

1.针对用户组权限位修改,用户创建的目录或文件所属组和该目录的所属组一致。
2.当某个目录设置了sgid后,在该目录中新建的文件不在是创建该文件的默认所属组
3.使用sgid可以使得多个用户之间共享一个目录的所有文件变得简单。
3.stitcky
sticky授权方法,1000 权限字符t(T),其他用户位的x位上设置。
# chmod 1755 /tmp
# chmod o+t /tmp

3.sticky role

1. multiple users have write permission, and so that each user can only delete their own files.
2. Special sticky catalog performance in the x position of others, with a small t said that if no execute permissions are T
3. Even if it is a directory permissions to "777" if the sticky bit is set, in addition to the owner and directories " root "users have permission to delete, in addition to other users are not allowed to delete the directory.

4.chattr

chatrr only the root user can use to modify the permissions attributes of the file system, authorized the establishment of the foundation above the rwx permissions.
chatrr command format: [root @ bgx ~] # chattr [+ - =] [ option] file or directory name

#选项: + 增加权限 -减少权限 =等于某个权限
# a:让文件或目录仅可追加内容
# i:不得任意更动文件或目录

1.希望任何人都不能创建用户
[[email protected] ~]# chattr +a /etc/passwd

2.sudo审计的日志文件非常的重要, 不允许别人删除.设定了权限还是正常记录.
[[email protected] ~]# chattr +a /var/log/secure
    #1.先备份
    cp secure secure_2019_00_00
    chattr -a secure
    > secure
    chattr +a secure

3.如果希望配置好的服务,对应的配置文件不希望任何人修改,添加+i参数即可.
    chattr +i /etc/rsyncd.conf

5.umask

umask表示要减去的权限,比如umask为022 目录拿777-022=755 文件拿666-022=644

系统默认的权限
[[email protected] ~]# umask
0022

当所有umask为偶数的时候 022
    目录: 777 - 022 = 755
    文件: 666 - 022 = 644

当所有umask为其中有部分为奇数的时候 032
    目录: 777 -032 = 745
    文件: 666 -032 = 6(3+1)4 644

当所有umask所有的为奇数的时候 033
    目录: 777 - 033 = 744
    文件: 666 - 033 = 6(3+1)(3+1) 644


root的权限是022,普通用户的权限是002

6. Summary

1.特殊权限:
    suid 使用户可以临时的拥有该命令的属主权限
    sgid 使多个用户之间共享一个目录变得更加的简单
    sbit 使该文件谁都可以创建,谁都给修改,但是允许删除自己的文件,不允许删除其他人的权限.

2.特殊属性: 不授rwx的限制
    chattr: 设定特殊属性: 
        +a 只能追加,通常用于日志这类的文件
        +i 锁定文件无法修改,无法做任何的操作,只能查看,比如重要的配置文件不希望被修改.
    lsattr: 查看文件是否存在特殊的属性

3.umask:表示要减去的权限:为了安全
    umask对文件和目录是有区别的
        umask为偶数的时候--> 目录正常 文件正常
        umask部分为奇数的时候-->目录正常 文件在奇数位+1
        umask都为奇数的时候--> 目录正常 文件在所有的奇数位+1




Guess you like

Origin www.cnblogs.com/Forever-x/p/7cdab0ed5a0499e89cbf7d1196497fac.html