RH124(6)----Linux系统中的权限管理_stripped, too many notes-程序员宅基地

一、权限查看及读取

1、权限查看

ls -l file ##查看文件权限
ls -ld dir ##查看目录权限

[root@localhost mnt]# ls -l westosfile
-rw-r--r--. 1 root root 0 Dec 16 20:31 westosfile
[root@localhost mnt]# ls -ld westosdir/
drwxr-xr-x. 2 root root 6 Dec 16 20:32 westosdir/

2、权限的读取

“文件的属性被叫做文件的元数据(meta data)”
“一种元数据用1个byte来记录内容”

#文件权限信息#
“-”| rw-r–r-- | . | 1 | root | root | 0 | Apr 12 10:57 | westos
[1]    [2]     [3] [4]   [5]    [6]  [7]     [8]          [9]

#目录权限信息#
d | rw-r–r-- | . | 2 | root | root | 0 | Apr 12 10:57 | westosdir
[1]    [2]    [3] [4]   [5]    [6]   [7]      [8]          [9]

#对于每一位的解释#
[1]      #文件类型
         #- 普通文件
         #d 目录
         #l 软连接
         #b 快设备
         #c 字符设备
         #s socket套接字
         #p 管道
[2]      ##用户权限
         ##rw -|r–|r–
         # u — g-- o
[3]      ##系统的selinux开启
[4]      ##对于文件:文件内容被系统记录的次数(硬链接个数)
         ##对于目录:目录中子目录的个数
[5]      ##文件拥有者
[6]      ##文件拥有组
[7]      ##对于文件:文件内容大小
         ##对于目录:目录中子文件的元数据大小
[8]      ##文件内容被修改的时间
[9]      ##文件名称
硬连接  一个节点对应多个数据区域
软连接 多个节点对应一个数据区域
[root@localhost mnt]# echo hello westos > westosfile
[root@localhost mnt]# file westosfile 
westosfile: ASCII text
[root@localhost mnt]# ls -l westosfile
-rw-r--r--. 1 root root 13 Dec 16 20:48 westosfile
[root@localhost mnt]# ln -s /mnt/westosfile /home/westos/Desktop/
[root@localhost mnt]# ls -l /home/westos/Desktop/westosfile 
lrwxrwxrwx. 1 root root 15 Dec 16 20:48 /home/westos/Desktop/westosfile -> /mnt/westosfile
[root@localhost mnt]# ls -l /dev/sr0
brw-rw----+ 1 root cdrom 11, 0 Dec 15 20:54 /dev/sr0
[root@localhost mnt]# ls -l /dev/pts/0
crw--w----. 1 westos tty 136, 0 Dec 16 20:09 /dev/pts/0

二、普通权限的类型及作用

1、用户对文件的身份

u: #user 文件的拥有者,ls -l 看到的第五列信息
g: #group 文件拥有组, ls -l 看到的第六列信息
o: #other 既不是拥有者也不是拥有组成员的其他用户的通称

[root@localhost mnt]# ls -l westos1
-rw-r--r--. 1 westos westos 0 Dec 17 09:50 westos1

2、权限位

rwx|r–|r–
u — g --o

3、用户身份匹配

user>group>other

4、权限类型

-     #权限未开启
r     #可读
      #对于文件:可以读取文件内容
      #对于目录:可以ls列出目录中的文件
w     #可写
      #对于文件:可以更改文件内容
      #对于目录:可以在目录中新建或者删除文件
x     #可执行
      #对于文件:可以用文件名称调用文件内记录的程序
      #对于目录:可以进入目录中

三、设定普通权限的方法

chmod       ##设定文件权限
#chmod 复制权限#
chmod --reference=/tmp /mnt/westosdir      ##复制/tmp目录的权限到/mnt/westosdir上
chmod -R --reference=/tmp /mnt/westosdir   ##复制/tmp目录的权限到/mnt/westosdir及目录中的子文件上 [-R 代表第归操作]
[root@localhost mnt]# chmod --reference=/mnt/westos1  /mnt/westos2
[root@localhost mnt]# chmod --reference=/mnt/westosdir /mnt/westos3

在这里插入图片描述

#chmod 字符方式设定权限
chmod <a|u|g|o><+|-|=><r|w|x> file ##用字副方式设定文件权限
a---all  u---user g---group  o---other
[root@localhost mnt]# chmod u-rw /mnt/westos1
[root@localhost mnt]# chmod u-rw /mnt/westosfile1
[root@localhost mnt]# chmod u-rw,g+x,o+wx /mnt/westosfile2
[root@localhost mnt]# chmod a-rwx /mnt/westosfile3
[root@localhost mnt]# chmod u=rwx,g=rx,o=--- /mnt/westosfile4
[root@localhost mnt]# chmod -R u=rwx,g=rx,o=--- /mnt/westosdir/
#chmod 数字方式设定权限#
权限波尔指表示方式
rwx = 111
--- = 000

三位二进制可以表示的最大范围为8进至数
rwx=111=7
rw-=110=6
r-x=101=5
r--=100=4=r
-wx=011=3
-w-=010=2=w
--x=001=1=x
---=000=0

chmod 600 /mnt/westosfile1
rw-------
布尔值 750-111=640  0-1=0
[root@localhost mnt]# chmod 640 westos3
[root@localhost mnt]# chmod 755 westos2
[root@localhost mnt]# chmod 742 westos1
[root@localhost mnt]# chmod -R 777 westosdir

在这里插入图片描述

四、系统默认权限设定

#系统本身存在的意义共享资源
#从安全角度讲系统共享的资源越少,开放的权力越小系统安全性越高
#既要保证系统安全,又要系统创造价值,于是把应该开放的权力默认开放
#把不安全的权力默认保留

#如何保留权力#
umask表示系统保留权力
umask #查看保留权力
umask 权限值 #临时设定系统预留权力

文件默认权限 = 777-umask-111
目录默认权限 = 777-umask

umask值越大系统安全性越高

umask临时更改
umask 077

[root@localhost mnt]# umask 077
[root@localhost mnt]# umask
0077
[root@localhost mnt]# touch westosfile1
[root@localhost mnt]# mkdir westosdir1

在这里插入图片描述

永久更改

[root@localhost mnt]# vim /etc/bashrc ##shell系统配置文件
74 if [ $UID -gt 199 ] && [ “id -gn” = “id -un” ]; then
75     umask 002  #普通用户的umask
76 else
77     umask 022 ---->077  #root用户的umask
78 fi

[root@localhost mnt]# vim /etc/profile ##系统环境配置文件
59 if [ $UID -gt 199 ] && [ “id -gn” = “id -un” ]; then
60     umask 002 #普通用户的umask
61 else
62     umask 022 --->077 #root用户的umask
63 fi
[root@localhost mnt]# source /etc/bashrc  ##source作用时使我们更改的内容立即被系统识别
[root@localhost mnt]# source /etc/profile 

五、文件用户用户组管理

chown username file ##更改文件拥有者
chgrp groupname file ##更改文件拥有组
chown username:groupname file ##同时更改文件的拥有者和拥有组
chown|chgrp -R user|group dir ##更改目录本身及目录中内容的拥有者或者拥有组

开启根目录权限查看监控,并在/mnt/下建立文件夹和文件
更改拥有者或者拥有组
在这里插入图片描述

[root@localhost mnt]# watch -n 1 "ls -lR /mnt/"
[root@localhost mnt]# chown lee /mnt/westos1
[root@localhost mnt]# chown lee.westos /mnt/westos2
[root@localhost mnt]# chown lee:westos /mnt/westos3
[root@localhost mnt]# chgrp lee /mnt/westosdir
[root@localhost mnt]# chgrp -R lee /mnt/westosdir
[root@localhost mnt]# chown -R lee /mnt/westosdir
[root@localhost mnt]# chown -R root.root /mnt/westosdir
[root@localhost mnt]# chown -R root.root /mnt/

六、特殊权限

stickyid 粘制位

#针对目录: #如果一个目录stickyid开启,那么这个目录中的文件只能被文件所有人删除

chmod 1原始权限 dir
chmod o+t dir

实验:
mkdir /mnt/pub
chmod 777 /mnt/pub

su - westos ----> touch /mnt/pub/westosfile
su - lee ----> touch /mnt//pub/leefile
rm -fr /mnt/pub/leefile #可以删除
rm -fr /mnt/pub/leefile #不属于自己的文件也可以删除

chmod 1777 /mnt/pub
chmod o+t /mnt/pub
以上两条命令都可以开启mnt/pub目录的t权限

[root@localhost mnt]# su - lee
[lee@localhost mnt]$ touch /mnt/pub/leefile
[lee@localhost mnt]$ logout
[root@localhost mnt]# su - linux
[linux@localhost mnt]$ touch /mnt/pub/linuxfile
[linux@localhost mnt]$ logout
[root@localhost linux]# chmod o+t /mnt/pub
[root@localhost linux]# su - lee
[lee@localhost ~]$ rm -fr /mnt/pub/leefile
[lee@localhost ~]$ rm -fr /mnt/pub/linuxfile
rm: cannot remove '/mnt/pub/linuxfile': Operation not permitted
[root@localhost home]# chmod 777 /mnt/pub
[root@localhost home]# chmod 1777 /mnt/pub

sgid 强制位

#针对目录: 目录中新建的文件自动归属到目录的所属组中

设定:
chmod 2源文件权限 dir
chmod g+s dir

[linux@localhost ~]$ id linux
uid=1003(linux) gid=1003(linux) groups=1003(linux),8000(shengchan)
[linux@localhost ~]$ touch /mnt/sc/file  ##是谁建立的文件组就是谁的
[linux@localhost ~]$ logout
[root@localhost mnt]# chmod g+s /mnt/sc
[root@localhost mnt]# su - linux
[linux@localhost ~]$ touch /mnt/sc/file1   ##file1自动复制了/mnt/sc目录组

在这里插入图片描述

[root@localhost mnt]# id linux
uid=1003(linux) gid=1003(linux) groups=1003(linux),8000(shengchan)
[linux@localhost ~]$ /bin/cat

[root@localhost mnt]# ls -l /bin/cat
-rwxr-xr-x. 1 root root 51856 Jan 11  2019 /bin/cat
[root@localhost mnt]# ps ax -o user,group,command | grep cat
gdm      gdm      /usr/libexec/gsd-print-notifications
westos   westos   /usr/libexec/gsd-print-notifications
westos   westos   /usr/bin/gnome-software --gapplication-service
linux    linux    /bin/cat
root     root     grep --color=auto cat
[root@localhost mnt]# chmod g+s /bin/cat
[root@localhost mnt]# ls -l /bin/cat
-rwxr-sr-x. 1 root root 51856 Jan 11  2019 /bin/cat
[root@localhost mnt]# ps ax -o user,group,command | grep cat
gdm      gdm      /usr/libexec/gsd-print-notifications
westos   westos   /usr/libexec/gsd-print-notifications
westos   westos   /usr/bin/gnome-software --gapplication-service
linux    root     /bin/cat
root     root     grep --color=auto cat
[root@localhost mnt]# ls -l /bin/cat
-rwxr-sr-x. 1 root root 51856 Jan 11  2019 /bin/cat

suid 冒险位

#只针对二进制的可执行文件(c程序)
#当运行二进制可执行文件时都是用文件拥有者身份运行,和执行用户无关

chmod 4原属性 file
chmod u+s file
在这里插入图片描述
超级用户不能删根

[root@localhost mnt]# useradd -s /sbin/nologin -M norm
[root@localhost mnt]# file /bin/rm
/bin/rm: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=943105ab9f2599b6725b5b90a4c05b549ce50beb, stripped, too many notes (256)
[root@localhost mnt]# chown norm.norm /bin/rm
[root@localhost mnt]# chmod ug+s /bin/rm 
[root@localhost mnt]# rm -fr /mnt/
rm: cannot remove '/mnt/.fiel1.swp': Permission denied
rm: cannot remove '/mnt/.file.swp': Permission denied
rm: cannot remove '/mnt/sc': Permission denied
[root@localhost mnt]# chmod 755 /bin/rm ##还原

七、acl权限列表

Aiccess Control Lists #访问控制列表

#功能:在列表中可以设定特殊用户对与特殊文件有特殊权限

acl列表开启标识

没有"+“代表acl列表未开启
drwxrwxrwx+ 2 root root 6 Dec 17 15:57 /mnt/westos
没有”+"代表acl列表未开启 “+”代表acl列表功能开启
在这里插入图片描述

acl列表权限读取

getfacl +文件名

显示内容分析
#file: westosfile #文件名称
#owner: root #文件拥有者
#group: root #文件拥有组
user::rw- #文件拥有者权限
user:lee:rw- #特殊指定用户权限
group::r-- #文件拥有组权限
group:westos:— #特殊指定的用户组的权限
mask::rw- #能够赋予特殊用户和特殊用户组的最大权限阀值
other::r-- #其他人的权限

“注意:“当文件权限列表开启,不要用ls -l 的方式来读取文件的权限”

acl列表的控制

setfacl -m u:westos:rwx /mnt/westos#设定
setfacl -m g:westos:rwx /mnt/westos
setfacl -m u::rwx /mnt/westos
setfacl -m g::0 /mnt/westos
setfacl -x u:westos /mnt/westos##删除列表中的westos
setfacl -b /mnt/westos #关闭

[root@localhost mnt]# mkdir westos
[root@localhost mnt]# chmod 777 /mnt/westos
[root@localhost mnt]# setfacl -m u:westos:0 /mnt/westos
[root@localhost mnt]# getfacl /mnt/westos
getfacl: Removing leading '/' from absolute path names
# file: mnt/westos
# owner: westos
# group: root
user::rwx
user:westos:---
group::rwx
mask::rwx
other::rwx
[root@localhost mnt]# su - westos
[westos@localhost ~]$ cd /mnt/westos
-bash: cd: /mnt/westos: Permission denied
[root@localhost mnt]# ls -ld /mnt/westos
drwxrwxrwx+ 2 root root 6 Dec 17 15:57 /mnt/westos

acl 权限优先级

拥有者 > 特殊指定用户 > 权限多的组 >权限少的组 > 其他
设置拥有者和特殊拥有者同一个,给特殊的满权限,拥有者0权限,切换到该用户在/mnt/guo/目录下建立文件,成功说明特殊的优先级别高,反之拥有者优先级高

acl mask 控制

mask是能够赋予指定用户权限的最大阀值
问题:当设定完毕文件的acl列表之后用chmod缩小了文件拥有组的权力,mask会发生变化
恢复:setfacl -m m:权限 文件
在这里插入图片描述
在这里插入图片描述

acl 列表的默认权限

setfacl -m u:lee:rwx /mnt/westosdir ##只对于/mnt/westosdir目录本身生效
setfacl -Rm u:lee:rwx /mnt/westosdir ##对于/mnt/westosdir目录和目录中已经存在的内容生效
#以上的命令之针对与存在的文件生效,新建文件是不会被设定的
setfacl -m d:u:lee:rwx /mnt/westosdir/ ##针对与/mnt/westosdir目录中新建文件生效
在这里插入图片描述

八、attr权限

#attr权限限制所有用户

i #不能作任何的更改
a #能添加不能删除

lsattr dir|file ##查看attr权限
chattr +i|+a|-i|-a dir|file ##设定attr权限

[root@localhost mnt]# mkdir westosdir
[root@localhost mnt]# chattr +a westosdir
[root@localhost mnt]# lsattr westosdir -d
-----a-------------- westosdir
[root@localhost mnt]# touch westosdir/file
[root@localhost mnt]# rm -fr westosdir/file
rm: cannot remove 'westosdir/file': Operation not permitted
[root@localhost mnt]# chattr -a westosdir
[root@localhost mnt]# rm -fr westosdir/file
[root@localhost mnt]# chattr +i westosdir/
[root@localhost mnt]# lsattr westosdir -d
----i--------------- westosdir
[root@localhost mnt]# touch westosdir/file
touch: setting times of 'westosdir/file': No such file or directory
[root@localhost mnt]# rm -fr westosdir/file
rm: cannot remove 'westosdir/file': Operation not permitted
[root@localhost mnt]# chattr -i westosdir/
[root@localhost mnt]# lsattr westosdir -d
-------------------- westosdir
[root@localhost mnt]# rm -fr westosdir/file
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_45777669/article/details/111301974

智能推荐

生活垃圾数据集(YOLO版)_垃圾回收数据集-程序员宅基地

文章浏览阅读1.6k次,点赞5次,收藏20次。【有害垃圾】:电池(1 号、2 号、5 号)、过期药品或内包装等;【可回收垃圾】:易拉罐、小号矿泉水瓶;【厨余垃圾】:小土豆、切过的白萝卜、胡萝卜,尺寸为电池大小;【其他垃圾】:瓷片、鹅卵石(小土豆大小)、砖块等。文件结构|----classes.txt # 标签种类|----data-txt\ # 数据集文件集合|----images\ # 数据集图片|----labels\ # yolo标签。_垃圾回收数据集

天气系统3------微服务_cityid=101280803-程序员宅基地

文章浏览阅读272次。之前写到 通过封装的API 已经可以做到使用redis进行缓存天气信息但是这一操作每次都由客户使用时才进行更新 不友好 所以应该自己实现半小时的定时存入redis 使用quartz框架 首先添加依赖build.gradle中// Quartz compile('org.springframework.boot:spring-boot-starter-quartz'..._cityid=101280803

python wxpython 不同Frame 之间的参数传递_wxpython frame.bind-程序员宅基地

文章浏览阅读1.8k次,点赞2次,收藏8次。对于使用触发事件来反应的按钮传递参数如下:可以通过lambda对function的参数传递:t.Bind(wx.EVT_BUTTON, lambda x, textctrl=t: self.input_fun(event=x, textctrl=textctrl))前提需要self.input_fun(self,event,t):传入参数而同时两个Frame之间的参数传..._wxpython frame.bind

cocos小游戏开发总结-程序员宅基地

文章浏览阅读1.9k次。最近接到一个任务要开发消消乐小游戏,当然首先就想到乐cocosCreator来作为开发工具。开发本身倒没有多少难点。消消乐的开发官网发行的书上有专门讲到。下面主要总结一下开发中遇到的问题以及解决方法屏幕适配由于设计尺寸是750*1336,如果适应高度,则在iphonX下,内容会超出屏幕宽度。按宽适应,iphon4下内容会超出屏幕高度。所以就需要根据屏幕比例来动态设置适配策略。 onLoad..._750*1336

ssm435银行贷款管理系统+vue_vue3重构信贷管理系统-程序员宅基地

文章浏览阅读745次,点赞21次,收藏21次。web项目的框架,通常更简单的数据源。21世纪的今天,随着社会的不断发展与进步,人们对于信息科学化的认识,已由低层次向高层次发展,由原来的感性认识向理性认识提高,管理工作的重要性已逐渐被人们所认识,科学化的管理,使信息存储达到准确、快速、完善,并能提高工作管理效率,促进其发展。论文主要是对银行贷款管理系统进行了介绍,包括研究的现状,还有涉及的开发背景,然后还对系统的设计目标进行了论述,还有系统的需求,以及整个的设计方案,对系统的设计以及实现,也都论述的比较细致,最后对银行贷款管理系统进行了一些具体测试。_vue3重构信贷管理系统

乌龟棋 题解-程序员宅基地

文章浏览阅读774次。题目描述原题目戳这里小明过生日的时候,爸爸送给他一副乌龟棋当作礼物。乌龟棋的棋盘是一行 NNN 个格子,每个格子上一个分数(非负整数)。棋盘第 111 格是唯一的起点,第 NNN 格是终点,游戏要求玩家控制一个乌龟棋子从起点出发走到终点。乌龟棋中 MMM 张爬行卡片,分成 444 种不同的类型( MMM 张卡片中不一定包含所有 444 种类型的卡片,见样例),每种类型的卡片上分别标有 1,2,3,41, 2, 3, 41,2,3,4 四个数字之一,表示使用这种卡片后,乌龟棋子将向前爬行相应的格子数

随便推点

python内存泄露的原因_Python服务端内存泄露的处理过程-程序员宅基地

文章浏览阅读1.5k次。吐槽内存泄露 ? 内存暴涨 ? OOM ?首先提一下我自己曾经历过多次内存泄露,到底有几次? 我自己心里悲伤的回想了下,造成线上影响的内存泄露事件有将近5次了,没上线就查出内存暴涨次数可能更多。这次不是最惨,相信也不会是最后的内存的泄露。有人说,内存泄露对于程序员来说,是个好事,也是个坏事。 怎么说? 好事在于,技术又有所长进,经验有所心得…. 毕竟不是所有程序员都写过OOM的服务…. 坏事..._python内存泄露

Sensor (draft)_draft sensor-程序员宅基地

文章浏览阅读747次。1.sensor typeTYPE_ACCELEROMETER=1 TYPE_MAGNETIC_FIELD=2 (what's value mean at x and z axis)TYPE_ORIENTATION=3TYPE_GYROSCOPE=4 TYPE_LIGHT=5(in )TYPE_PRESSURE=6TYPE_TEMPERATURE=7TYPE_PRO_draft sensor

【刘庆源码共享】稀疏线性系统求解算法MGMRES(m) 之 矩阵类定义三(C++)_gmres不构造矩阵-程序员宅基地

文章浏览阅读581次。/* * Copyright (c) 2009 湖南师范大学数计院 一心飞翔项目组 * All Right Reserved * * 文件名:matrix.cpp 定义Point、Node、Matrix类的各个方法 * 摘 要:定义矩阵类,包括矩阵的相关信息和方法 * * 作 者:刘 庆 * 修改日期:2009年7月19日21:15:12 **/

三分钟带你看完HTML5增强的【iframe元素】_iframe allow-top-navigation-程序员宅基地

文章浏览阅读1.7w次,点赞6次,收藏20次。HTML不再推荐页面中使用框架集,因此HTML5删除了&lt;frameset&gt;、&lt;frame&gt;和&lt;noframes&gt;这三个元素。不过HTML5还保留了&lt;iframe&gt;元素,该元素可以在普通的HTML页面中使用,生成一个行内框架,可以直接放在HTML页面的任意位置。除了指定id、class和style之外,还可以指定如下属性:src 指定一个UR..._iframe allow-top-navigation

Java之 Spring Cloud 微服务的链路追踪 Sleuth 和 Zipkin(第三个阶段)【三】【SpringBoot项目实现商品服务器端是调用】-程序员宅基地

文章浏览阅读785次,点赞29次,收藏12次。Zipkin 是 Twitter 的一个开源项目,它基于 Google Dapper 实现,它致力于收集服务的定时数据,以解决微服务架构中的延迟问题,包括数据的收集、存储、查找和展现。我们可以使用它来收集各个服务器上请求链路的跟踪数据,并通过它提供的 REST API 接口来辅助我们查询跟踪数据以实现对分布式系统的监控程序,从而及时地发现系统中出现的延迟升高问题并找出系统性能瓶颈的根源。除了面向开发的 API 接口之外,它也提供了方便的 UI 组件来帮助我们直观的搜索跟踪信息和分析请求链路明细,

烁博科技|浅谈视频安全监控行业发展_2018年8月由于某知名视频监控厂商多款摄像机存在安全漏洞-程序员宅基地

文章浏览阅读358次。“随着天网工程的建设,中国已经建成世界上规模最大的视频监控网,摄像头总 数超过2000万个,成为世界上最安全的国家。视频图像及配套数据已经应用在反恐维稳、治安防控、侦查破案、交通行政管理、服务民生等各行业各领域。烁博科技视频安全核心能力:精准智能数据采集能力:在建设之初即以应用需求为导向,开展点位选择、设备选型等布建工作,实现前端采集设备的精细化部署。随需而动的AI数据挖掘能力:让AI所需要的算力、算法、数据、服务都在应用需求的牵引下实现合理的调度,实现解析能力的最大化。完善的数据治理能力:面_2018年8月由于某知名视频监控厂商多款摄像机存在安全漏洞