Linux Rights Management

One: ACL permissions

The operation of authorizing or reclaiming permissions by specifying a user or specifying a user group alone for a file or directory is understood as ACL permissions

access control lists abbr

 

Check whether the partition ACL permission is enabled

dumpe2fs This command is a file system command and is understood in the file system command.

dumpe2fs -h filesystem

df -h View the file system corresponding to the root partition.

Default mount options:    user_xattr acl

 

Temporarily enable partition ACL permissions

mount -o remount, acl / Remount the root partition and mount it with acl permissions.

 

Permanently enable partition ACL permissions

vi /etc/fstab

Add, acl after the default of the root partition and then restart the system or remount the file (mount -o remount /)

 

 

View ACL permissions 

Syntax: getfacl filename

 

Note: When using ll to view the file, if there is a + sign like the following, it means that you have acl permission.

drwxr-x---+ 2 root root 4096 Jul  3 07:37 /project/

 

Set ACL permissions

Syntax: setfacl option filename

Options:

-m Set ACL permissions

eg:setfacl -mu:tu:rx /project/ Set ACL permission rx for user tu (read and execute)

eg:setfacl -mg:tg:rwx /project/ Set ACL permission rwx (read, write and execute) for user group tg

 

maximum effective permission mask

mask is used to specify the maximum effective permissions. We have given ACL permissions to users, which need to be "compared to" with the permissions of the mask to have real permissions.

 

Set maximum effective permissions

setfacl -mm:rx /project/ sets maximum permissions to read and execute.

 

Remove ACL permissions

a, delete the specified user acl permissions: setfacl -xu: user name file name

  eg:setfacl -xu:tu /project/ Delete the ACL permission of the specified user (tu) to the file (/project/)

  Delete the acl permissions of the specified user group: setfacl -xg: user group name file name

  eg:setfacl -x g:tg /project/  删除指定用户组(tg)对文件(/project/)的ACL权限

b,删除指定文件的所有acl权限:setfacl -b 文件名

  eg:setfacl -b /project/  删除文件(/project/)的ACL权限

 

递归ACL权限(-R)

setfacl -m u:用户名:权限 -R 文件名

注意:上面的命令对命令之后产生的文件是不生效的。

 

默认ACL权限

默认ACL权限的作用是如果给定父目录设定了ACL权限 那么父目录中所创建的子文件都会继承父目录的ACL权限

setfacl -m d:u:用户名:权限 文面名

eg:setfacl -m d:u:tu:rx /project/

注意该命令不会对已经目录(/project/)下已经存在的子目录生效只会对不存在后面加入的文件或目录生效。

若想对已经存在的子文件或者子目录生效要将命令改为:setfacl -m d:u:tu:rx -R /project/

 

二:特殊权限

SetUID     4

1,理解:

a,只有对可以执行的二进制程序才能设定SUID权限

b,命令执行者要对改程序拥有x(执行)权限

c,命令执行者在执行该程序时获得该程序文件属主的身份(在执行过程中灵魂附体为文件的属主)

d,SetUID权限志在该程序执行过程中有效,也就是说身份改变只在程序执行过程中有效。

 

2,设定SetUID的方法(两种)

   4代表SUID

   chmod 4755 文件名

   chmod u+s 文件名

 

3,取消SetUID的方法

   chmod 755 文件名

   chmod u-s 文件名

 

4,危险的SetUID

a,关键目录应该严格控制读写权限,比如:/ 或 /usr/

b,

 

setGID     2

理解:

针对文件时:

a,只有对可以执行的二进制程序才能设定SUID权限

b,命令执行者要对改程序拥有x(执行)权限

c,命令执行者在执行该程序时获得该程序文件属组的身份(在执行过程中灵魂附体为文件的属组)

d,SetUID权限志在该程序执行过程中有效,也就是说身份改变只在程序执行过程中有效。

和SetUID非常相似。

 

针对目录时:

用的少,以后真有用的时候再回过头来看 20160703 8.2.2

 

2,设定SetGID的方法(两种)

   4代表SGID

   chmod 2755 文件名

   chmod g+s 文件名

 

3,取消SetGID的方法

   chmod 755 文件名

   chmod u-s 文件名

 

Sticky BIT  1 sticky(粘着位)

粘着位理解

a,粘着位目前只对目录有效。

b,普通用户对该目录拥有w和x权限,即普通用户可以在此目录拥有写入权限

c,如果没有粘着位,因为普通用户拥有w权限,所以可以删除此目录下的所有文件,

包括其他用户建立的文件。一旦赋予了粘着位,除了root可以删除所有文件,

普通用户就算拥有w权限,也只能删除自己建立的文件,但不能删除其它用户建立的文件

 

2,设定粘着位的方法(两种)

   4代表SGID

   chmod 1755 文件名

   chmod o+t 文件名

 

3,取消粘着位的方法

   chmod 755 文件名

   chmod o-t 文件名

 

 

文件系统属性chattr权限

语法:chattr [+-=] [选项] 文件名

   +   增加权限

   -   删除权限

   =   等于某权限

选项   

   i 如果对文件设置i属性,那么不允许对文件进行删除、改名,也不能添加和修改数据。

如果对目录设置i属性,那么只能修改目录下文件的数据,但不允许建立和删除文件。是immutable的缩写

   a如果对文件设置a属性,那么能对文件增加数据,不能修改和删除数据。

如果对目录设置a属性,那么只允许在目录中建立和修改文件,不允许删除。是append的缩写

以上选项对root也生效。   

   

查看文件系统属性   lsattr [选项] 文件名

选项:

-a 显示所有文件和目录

-d 目标是目录,仅仅列出目录本身的属性,而不是子文件的

 

echo 11111 >> abc.txt 用追加重定向的方式往文件abc.txt中写入内容11111

 

系统命令sudo权限

1,sudo权限

    a,把本来只能超级用户执行的命令赋予普通用户执行。

    b,sudo的操作对象是系统命令

2,sudo使用

 visudo     #实际修改的是/etc/sudoers文件

 

 root All=(All)  All

#用户名 被管理主机的IP地址=(可使用的身份)   授权命令(绝对路径)

 

  %wheel  All=(All)  All

  组名    被管理主机的地址=(可以使用的身份)   授权命令(绝对路径)

eg: 授权sc用户可以执行重启服务器的的命令是:

  visudo

  sc  All= /sbin/shutdown -r now

 

普通用户执行sudo赋予的命令

su - sc    #从当前用户切换到sc用户

sudo -l    #查看可用的sudo命令

sudo /sbin/shutdown -r now   #普通用户执行sudo赋予的命令

 

注意:将vim命令授予给普通用户这个操作要慎重(不推荐)

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326575433&siteId=291194637