19_linux笔记-用户权限


博客cpen_web

回顾1

/目录下的 /etc 一般放配置文件
一个用户的基本组只能有一个,附属组可以有多个;享受的权限是一样的,都是有那个组的权限

示例

[root@sanchuang-linux ~]# useradd sanle10
[root@sanchuang-linux ~]# id sanle10
uid=2224(sanle10) gid=2224(sanle10)=2224(sanle10)
[root@sanchuang-linux ~]# less /etc/group
[root@sanchuang-linux ~]# useradd sanle11 -g sanchuang05 -G sanchuang06	# 指定基本组、附属组
[root@sanchuang-linux ~]# id sanle11
uid=2225(sanle11) gid=1043(sanchuang05)=1043(sanchuang05),1044(sanchuang06)
[root@sanchuang-linux ~]# less /etc/passwd				# 注:存放用户信息
hello:x:1007:1007::/home/hello:/bin/bash
# 注:字段2仅仅只是密码占位符,真正的密码放在/etc/shadow
[root@sanchuang-linux ~]# ls -al /etc/passwd
-rw-r--r-- 1 root root 4539 11月 12 09:50 /etc/passwd	# 注:任何人都可以访问/etc/passwd
[root@sanchuang-linux ~]# ls -al /etc/shadow
---------- 1 root root 4588 11月 12 09:50 /etc/shadow		# 注:权限都为0

[root@sanchuang-linux ~]# useradd sanle13 -c "create sanle13"	# 注:指定用户描述信息
[root@sanchuang-linux ~]# less /etc/passwd
sanle13:x:2227:2227:create sanle13:/home/sanle13:/bin/bash	# 注:字段5用户描述信息

[root@sanchuang-linux tmp]# ls -ld /lianxi	# 注:查看/lianxi 目录属于哪个用户哪个组
drwxr-xr-x. 9 root root 4096 11月  9 09:47 /lianxi

# 普通用户默认只能在自己的家目录下 或 /tmp目录下创建

对个人环境信息做设置
~/.bash_profile
~/.bashrc

[root@sanchuang-linux tmp]# id sanle11
uid=2225(sanle11) gid=1043(sanchuang05)=1043(sanchuang05),1044(sanchuang06)	# 注:基本组sanchuang05
[root@sanchuang-linux tmp]# su - sanle11
[sanle11@sanchuang-linux ~]$ touch cc
[sanle11@sanchuang-linux ~]$ ls -al
总用量 16
……………………
-rw-r--r--   1 sanle11 sanchuang05    0 11月 12 10:21 cc	# 注:有效组sanchuang05
# 注:有效组默认是用户基本组
[sanle11@sanchuang-linux ~]$ newgrp sanchuang06			# 注:修改有效组;临时修改
[sanle11@sanchuang-linux ~]$ touch dd
[sanle11@sanchuang-linux ~]$ ls -al
……………………
-rw-r--r--   1 sanle11 sanchuang06    0 11月 12 10:23 dd	# 注:有效组sanchuang06

练习2

题目1

创建三个用户sx1,sx2,sx3,这三个用户的附属组都是sanle组,创建名为/home/sanle的目录,在该目录中,三个用户可以合作>处理文件。要求恰当修改该目录的权限,以便只允许用户和组能在这个目录中访问、删除、创建文件,其他用户没有任何权限,>三个用户新建的文件只能自己有权限删除,彼此无法删除,而且新建的文件应该被自动分配到sanle的组所有权。

示例

#创建三个用户sx1,sx2,sx3,这三个用户的附属组都是sanle组,创建名为/home/sanle的目录,在该目录中,三个用户可以合作>处理文件。要求恰当修改该目录的权限,以便只允许用户和组能在这个目录中访问、删除、创建文件,其他用户没有任何权限,>三个用户新建的文件只能自己有权限删除,彼此无法删除,而且新建的文件应该被自动分配到sanle的组所有权。
useradd -G sanle sx1
useradd -G sanle sx2
useradd -G sanle sx3
mkdir /home/sanle
newgrp sanle
mkdir /home/sanle
chmod 1770 /home/sanle -R
echo "newgrp sanle" >> ~/.bashrc

题目2 脚本

1、创建用户
2、删除指定用户
3、修改指定用户(用户id,用户属组,用户家目录)
4、删除指定用户

示例1

#!/bin/bash
menu(){
    echo "1、创建用户"
    echo "2、删除指定用户"
    echo "3、修改指定用户(用户id,用户属组,用户家目录)"
    echo "4、删除指定用户"
}

add(){
    read -p "输入用户名:" username			# 注:接收从键盘的输入
    useradd $username &>/dev/null && echo "创建成功" || echo "创建失败"
}

del(){
    read -p "输入用户名:" username
    userdel -r $username &>/dev/null && echo "删除成功" || echo "用户不存在"
}

modify(){
    read -p "输入用户名:" username
    id $username &>/dev/null
    if [[ $? = 0 ]]
    then
        read -p "输入uid:" uid				# 注:可以再加3个case 更精细
        read -p "输入gid:" gid
        read -p "输入家目录:" home
        usermod -u $uid -g $gid -d $home $username 2>/dev/null && echo "修改成功" || "修改失败"
    else
        echo "用户不存在"
    fi
}

while :
do
    menu
    read -p "请输入1-4:" option
    case $option in
    1)
        add
        ;;
    2)
        del
        ;;
    3)
        modify
        ;;
    4)
        del
        ;;
    *)
        echo "输入不合法"
    esac
done

示例2:一次性添加多个变量

mod(){
	read -p "请输入(用户id,用户属组,用户家目录):" userid usergroup userhome username
       usermod -u $userid -g $usergroup -d $userhome $username &> /dev/null && echo "修改成功" || echo "修改失败"	
}

示例3:精密选择(推荐)

#!/bin/bash

menu(){
    echo "1、创建用户"
    echo "2、删除指定用户"
    echo "3、修改指定用户(用户id,用户属组,用户家目录)"
}
menu2(){
    echo "1、修改用户id"
    echo "2、修改用户属组"
    echo "3、修改用户家目录"

}

add(){
    read -p "输入用户名:" username
    id $username &>/dev/null &&echo "用户已存在" || useradd $username &>/dev/null && echo "创建成功" || echo "创建失败"
}

del(){
    read -p "输入用户名:" username
    id $username &>/dev/null || echo "用户不存在" && userdel -r $username &>/dev/null && echo "删除成功" || echo "删除失败"
}

modify(){
    read -p "输入用户名:" username
    if id $username &>/dev/null
    then
	menu2
	read -p "请输入:" choice2
	case $choice2 in
	1)
	    read -p "输入uid:" uid
	    usermod -u $uid $username &>/dev/null && echo "修改成功" || echo "修改失败"
	;;
	2)
	    read -p "输入gid:" gid
	    usermod -g $gid &>/dev/null && echo "修改成功" || echo "修改失败"
	;;
	3)
	    read -p "输入家目录:" home
	    usermod -d $home $username &>/dev/null && echo "修改成功" || echo "修改失败"
	;;
	*)
	echo "输入不合法"
	esac
    else
        echo "用户不存在"
    fi
}

while true
do
    menu
    read -p "请输入(按q退出):" choice
    case $choice in
    1)
        add
        ;;
    2)
        del
        ;;
    3)
        modify
        ;;
    q)
	break
	;;
    *)
        echo "输入不合法"
    esac
done

知识点3 ACL的使用

ACL(Access Control List) # 注:访问控制列表(允许哪些人可以/不可以访问)
·一个文件/目录的访问控制列表,可以针对任意指定的 用户/组使用权限字符分配rwx权限

设置ACL:setfacl指令
·格式: setfacl 选项 规则 文件
常用选项
·-m:新增或修改ACL中的规则
·-b: 删除所有ACL规则
·-x: 删除指定的ACL规则

查看ACL:getfacl指令
·格式:getfacl 文件

设置ACL:setfacl指令
·格式: setfacl 选项 规则 文件
常用规则
·格式:类型:特定的用户或组:权限
·user:(uid/name):(perms) 指定某位使用者的权限
·group:(gid/name):(perms) 指定某一群组的权限
·other::(perms) 指定其它使用者的权限
·mask::(perms) 设定有效的最大权限

注意
·user、group、other、mask简写为:u , g , o , m
·perms使用rwx

#注:acl访问控制列表,工作中和云计算都比较常见

示例1:查看文件acl

#注:对权限精准把控
[root@localhost ~]# getfacl win-utf-2.txt 	# 注:查看文件acl规则
# file: win-utf-2.txt						# 注:get file acl
# owner: root								# 注:初始的规则
# group: root
user::rw-
group::r--
other::r--
[root@localhost ~]# ls -la win-utf-2.txt 
-rw-r--r--. 1 root root 0 10月 27 11:42 win-utf-2.txt
[root@localhost ~]# 

示例2:对sanchuang用户有读写执行权限

#注:针对特殊用户

[root@localhost ~]# setfacl -m u:sanchuang:rwx win-utf-2.txt 	# 注:对sanchuang用户有rwx权限
[root@localhost ~]# getfacl win-utf-2.txt 				# 注:u也可以写成 user  一般简写
# file: win-utf-2.txt						# 注:注意普通用户对/root目录没有操作权限
# owner: root
# group: root
user::rw-
user:sanchuang:rwx							# 注:对sanchuang用户有rwx权限
group::r--
mask::rwx
other::r--
[root@localhost ~]# ls -la win-utf-2.txt 		# 注:权限多了个+
-rw-rwxr--+ 1 root root 0 10月 27 11:42 win-utf-2.txt

示例3:对组有读写执行的权利

#注:针对特定组

[root@localhost ~]# setfacl -m g:sanchuang5:rw win-utf-2.txt 
[root@localhost ~]# ls -la win-utf-2.txt 		# 注:set file acl
-rw-rwxr--+ 1 root root 0 10月 27 11:42 win-utf-2.txt
[root@localhost ~]# getfacl win-utf-2.txt 
# file: win-utf-2.txt
# owner: root
# group: root
user::rw-
user:sanchuang:rwx
group::r--
group:sanchuang5:rw-						# 注:对组有读写执行的权利
mask::rwx
other::r--

示例4:设置有效的最大权限

#注:针对mask设置有效权限

#注:设定有效的最大权限为r
#注:设置的权限在mask之下(天花板)
[root@localhost ~]# setfacl -m m::r win-utf-2.txt		# 注:设置有效的最大权限
[root@localhost ~]# getfacl win-utf-2.txt 
# file: win-utf-2.txt
# owner: root
# group: root
user::rw-
user:sanchuang:rwx		#effective:r--		# 注:即使sanchuang的权限是rw,但是有效最大权限是r
group::r--
group:sanchuang5:rw-		#effective:r--
mask::r--
other::r--
#注:指明了有效最大权限后;用户sanchuang即使有读写的权限,用户sanchuang5最大权限仅仅指为读
#注:即使设置了用户sanchuang rw权限,但是mask设置为r,也只有r的权限

知识点4 ACL类型

ACL类型
·存取型ACL(Access ACL):文件或目录
·预设型ACL(Default ACL):只能对目录
预设型ACL(Default ACL)
·格式:setfacl –m default:类型:特定的用户或组:权限
setfacl –m d:类型:特定的用户或组:权限
·设置了预设型ACL的目录,其下的所有文件或者子目录就都具有了主目录的ACL权限,并且子目录也同样有预设的ACl权限

#注:只能对目录设置预设型

示例 设置预设ACL

[root@sanchuang-linux lianxi]# mkdir cc_test
[root@sanchuang-linux lianxi]# getfacl cc_test/
# file: cc_test/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
[root@sanchuang-linux lianxi]# setfacl -m d:u:sanle10:rw cc_test/	 # 注:对文件进行预设型acl设置
[root@sanchuang-linux lianxi]# getfacl cc_test/
# file: cc_test/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
default:user::rwx							# 注:新增的参数
default:user:sanle10:rw-
default:group::r-x
default:mask::rwx
default:other::r-x
[root@sanchuang-linux lianxi]# cd cc_test/
[root@sanchuang-linux cc_test]# touch aa		# 注:新建的文件会继承预设的acl设置
[root@sanchuang-linux cc_test]# getfacl aa
# file: aa
# owner: root
# group: root
user::rw-
user:sanle10:rw-							# 注:新建的文件会继承预设的acl设置
group::r-x			#effective:r--
mask::rw-
other::r--
#注:预设之前已经创建的文件 不会继承预设的acl设置

练习5

1、新建三个组 shuiguo, mifeng, shaokao
2、新建3个用户,pingguo属于shuiguo组,jingshi属于mifen组,yueyang属于shaokao组
3、在根目录下新建目录food,将/etc/passwd文件复制到food目录下
4、设置权限,passwd文件能被shuiguo组读写,jingshi这个用户读写执行,yueyang这个用户不能进行任何操作

示例

#1
[root@sanchuang-linux lianxi]# groupadd shuiguo
[root@sanchuang-linux lianxi]# groupadd mifen
[root@sanchuang-linux lianxi]# groupadd shaokao
#2
[root@sanchuang-linux lianxi]# useradd -g shuiguo pingguo
[root@sanchuang-linux lianxi]# useradd -g mifen jingshi
[root@sanchuang-linux lianxi]# useradd -g shaokao yueyang
#3
[root@sanchuang-linux lianxi]# mkdir /food
[root@sanchuang-linux lianxi]# cp /etc/passwd /food
[root@sanchuang-linux lianxi]# cd /food
#4
[root@sanchuang-linux food]# setfacl -m g:shuiguo:rw passwd 
[root@sanchuang-linux food]# setfacl -m u:jingshi:rwx passwd 
[root@sanchuang-linux food]# setfacl -m u:yueyang:--- passwd
[root@sanchuang-linux food]# getfacl passwd 
# file: passwd
# owner: root
# group: root
user::rw-
user:jingshi:rwx
user:yueyang:---
group::r--
group:shuiguo:rw-
mask::rwx
other::r--

知识点6 权限的继承和拒绝

一个用户属于某个组会继承这个组的权限。
1.主要组
2.次要组

用户的主要组(有效组)属于某个组,会继承这个组的权限,如果是附属组属于某个组,也会继承。
·newgrp

拒绝权限高于一切 —》针对用户

一个组允许,一个组拒绝 —》允许

知识点7 sudo授权

sudo授权
·Linux里root用户权限最大
关机、重启系统、配置IP地址、格式化磁盘、mount等
·普通用户权限非常小
·如何让普通用户也具有一定的权限?
给root用户分忧
·如果能授权,那么是授权给用户还是组?

#注:sudo授权给部分普通用户使用root用户的权限
#注:sudo --> 授权给普通用户取执行命令的
#注:sudo配置文件 /etc/sudoers
#注:有一个日志文件会记录下被授权者执行的所有命令 /var/log/secure

#注:第一个ALL表示允许任何终端、机器访问sudo,一般就表示本机
#注:第二个ALL表示sudo命令可以允许以任何用户身份去执行
#注:第三个ALL表示可以执行任何命令

授权日志:有一个日志文件会记录下被授权者执行的所有命令 /var/log/secure
查看日志,知道授权命令的执行情况

[root@cali ~]# tailf /var/log/secure

示例1:生成随机密码

#注:生成随机密码的工具 mkpasswd
https://www.cnblogs.com/shijunxian/archive/2020/05/26/12961543.html

[root@sanchuang-linux food]# yum install expect -y
[root@sanchuang-linux bin]# mkpasswd -l 15 -d 3 -c 4 -C 4 -s 2
wjp4[HC]hx6mSO6

示例2:sudo配置文件 /etc/sudoers

#注:授权给某些用户执行某些命令
#注:编辑/etc/sudoers授权并验证

[root@sanchuang-linux bin]# less /etc/sudoers
………………
## Syntax:
##
##      user    MACHINE=COMMANDS		………………
## Allow root to run any commands anywhere 
root    ALL=(ALL)       ALL					# 注:ALL表示当前这个机器
#注:1、允许root用户执行这条命令 ; 2、ALL表示当前这个主机,(ALL)表示允许用户以哪个用户的权限设置 ; 3、ALL表示所有命令(在这个机器上面可以有任何用户的命令)

#注:第一个ALL表示允许任何终端、机器访问sudo,一般就表示本机
#注:第二个ALL表示sudo命令可以允许以任何用户身份去执行
#注:第三个ALL表示可以执行任何命令

示例3:编辑配置文件/etc/sudoers 给用户颁布权限

#注:编辑配置文件 可以使用vim 也可以使用visudo 使用visudo不需要接文件名
#注:推荐使用visodu去编辑/etc/sudoers,它会检测语法;vim去编辑不会检测
#注:对于用户sanle有本地host所有权限

[root@sanchuang-linux bin]# visudo			# 注:使用visudo不需要接文件名
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
sanle   ALL=(ALL)       ALL					
#注:表示sanle用户,可以在这台主机上执行任何用户的任何命令,但是使用sudo执行时需要输入sanle用户的密码
#注:不设置NOPASSWD  第1次输入密码后  密码有时效性
[root@sanchuang-linux bin]# su - sanle		# 注:切换到sanle用户
[sanle@sanchuang-linux ~]$ sudo passwd wy		# 注:前面+sudo  能进行任何操作
我们信任您已经从系统管理员那里了解了日常注意事项。
总结起来无外乎这三点:
    #1) 尊重别人的隐私。
    #2) 输入前要先考虑(后果和风险)。
    #3) 权力越大,责任越大。
[sudo] sanle 的密码:						# 注:需要输入sanle用户 密码
[root@sanchuang-linux bin]# visudo 
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
sanle   ALL=(ALL)       NOPASSWD:ALL	
#注:表示sanle用户,可以在这台主机上执行任何用户的任何命令,无需输入sanle的密码
[sanle@sanchuang-linux ~]$ sudo passwd wy
更改用户 wy 的密码 。
新的 密码:								# 注:不需要验证原密码

示例4:给用户/组颁布权限

[root@sanchuang-linux bin]# visudo 
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
sanle   ALL=(ALL)       NOPASSWD:ALL	
#注:表示sanle用户,可以在这台主机上执行任何用户的任何命令,无需输入sanle的密码
%sanchuang5 ALL=(ALL)   NOPASSWD:ALL		
#注:表示sanchuang5这个组的用户,在这台主机上可以执行任何用户的任何命令,无需输入密码

#注:对于sanchuang5这个组赋予以任何用户执行任何权限
#注:组里的所有成员也会拥有这个权限

示例5 对于指定的命令去授权

[sanle@sanchuang-linux ~]$ which chown
/usr/bin/chown
[sanle@sanchuang-linux ~]$ which passwd
/usr/bin/passwd
[root@sanchuang-linux cc_test]# visudo
root    ALL=(ALL)       ALL
sanle   ALL=(ALL)       NOPASSWD:ALL
%sanchuang5 ALL=(ALL)   NOPASSWD:ALL
wy      ALL=(ALL)       /usr/bin/chown,/usr/bin/passwd		# 注:接命令的绝对路径
#注:表示wy用户在这台主机上,拥有chown,passwd命令执行授权,命令路径写命令的绝对路径
[wy@sanchuang-linux ~]$ sudo chmod 777 aa
我们信任您已经从系统管理员那里了解了日常注意事项。
总结起来无外乎这三点:
    #1) 尊重别人的隐私。
    #2) 输入前要先考虑(后果和风险)。
    #3) 权力越大,责任越大。
[sudo] wy 的密码:										# 注:验证密码后可以修改
[wy@sanchuang-linux ~]$ sudo passwd wy2
更改用户 wy2 的密码 。
新的 密码:

示例6:授权日志 /var/log/目录下 secure文件

#注:有一个日志文件会记录下被授权者执行的所有命令 /var/log/secure

[root@sanchuang-linux cc_test]# cd /var/log/
[root@sanchuang-linux log]# less secure				
uid=0 tty=/dev/pts/2 ruser=wy rhost=  user=wy
Nov 12 16:43:26 sanchuang-linux sudo[2424]: pam_unix(sudo:auth): conversation failed
Nov 12 16:43:26 sanchuang-linux sudo[2424]: pam_unix(sudo:auth): auth could not identify password for [wy]
Nov 12 16:43:26 sanchuang-linux sudo[2424]: wy : command not allowed ; TTY=pts/2 ; PWD=/home/wy ; USER=root
 ; COMMAND=/bin/chmod 777 aa

示例7

[root@sanchuang-linux bin]# ls -ld /bin/passwd
-rwsr-xr-x. 1 root root 33600 4月   7 2020 /bin/passwd
#注:s位  普通用户有设置密码的权限,但是没有为他人设置密码的权限,且密码需要满足密码复杂度

练习8

yum install net-tools -y
授予bailongma用户:useradd、userdel、passwd
授予baigujing用户:ip、ping、ifconfig、route
授权yutujing用户:poweroff、reboot

#注:授权不会检测系统里有该用户

示例1

[wy@sanchuang-linux ~]$ which useradd				# 注:查找命令的绝对路径
/usr/sbin/useradd
………………………………
[wy@sanchuang-linux ~]# visudo
root    ALL=(ALL)       ALL
bailongma ALL=(ALL)     /usr/sbin/useradd,/usr/sbin/userdel,/usr/bin/passwd
baigujing ALL=(ALL)     /usr/sbin/ip,/usr/bin/ping,/usr/sbin/ifconfig,/usr/sbin/route
yutujing  ALL=(ALL)     /usr/sbin/poweroff,/usr/sbin/reboot

示例2:(ALL) 可以不写

[wy@sanchuang-linux ~]# visudo
root    ALL=(ALL)       ALL
bailongma ALL=/usr/sbin/useradd,/usr/sbin/userdel,/usr/bin/passwd		# 注:(ALL) 可以不写
baigujing ALL=/usr/sbin/ip,/usr/bin/ping,/usr/sbin/ifconfig,/usr/sbin/route
yutujing  ALL=/usr/sbin/poweroff,/usr/sbin/reboot

示例3:定义别名

[wy@sanchuang-linux ~]# visudo
#定义命令别名
Cmnd_Alias  NETWORK = /usr/sbin/ip,/usr/bin/ping,/usr/sbin/ifconfig,/usr/sbin/route
Cmnd_Alias  SHUT = /usr/sbin/poweroff,/usr/sbin/reboot
Cmnd_Alias  USER = /usr/sbin/useradd,/usr/sbin/userdel,/usr/bin/passwd

bailongma ALL=USER,NETWORK
baigujing ALL=NETWORK
yutujing  ALL=SHUT
[baigujing@sanchuang-linux ~]$ sudo ip a add 192.168.0.144/24 dev ens33  #注:为网卡增加ip地址
[sudo] baigujing 的密码:								# 注:ip命令权限的使用
[baigujing@sanchuang-linux ~]$ ip add
………………
    inet 192.168.0.26/24 brd 192.168.0.255 scope global dynamic noprefixroute ens33
    inet 192.168.0.144/24 scope global secondary ens33
………………

#注:为网卡增加ip地址(1个网卡可以有多个ip地址)

[wy@sanchuang-linux ~]$ ip a add 192.168.0.144/24 dev ens33

知识点9 SELinux介绍

·SELinux是什么?有什么用?
·如何查看SELinux是否开启?
getenforce
·如何关闭和开启SELinux?
临时
setenforce
永久
修改配置文件
vim /etc/selinux/config
vim /etc/sysconfig/selinux
重新启动系统
·SELinux在企业里使用多吗?

SELinux是什么?
·SELinux是一个linux系统里的一个安全方面的子系统,用来提升linux的整体的安全级别。是一种访问控制体系,进程只能访问那些在他的任务中所需要文件。(控制进程可以访问哪些允许访问的资源)

·操作系统有两类访问控制:自主访问控制(DAC)和强制访问控制(MAC)。

·标准Linux安全是一种DAC,SELinux为Linux增加了一个灵活的和可配置的的MAC。

·DAC(Discretionary Access Control)自主访问控制

·工作原理:

·MAC(Mandatory Access Control)―――强制访问控制 —》selinux

·工作原理:

·哪些进程能访问哪些类型的文件,都有安全策略

永久修改
#注:这是链接文件 /etc/sysconfig/selinux -> /etc/selinux/config

[root@cali log]# vim /etc/sysconfig/selinux
SELINUX=disabled

临时配置
临时配置,重新启动系统会失效
0–》Permissive 宽容模式
1–》Enforcing 强制执行模式

[root@cali selinux]# setenforce 0  
[root@cali selinux]# getenforce  
Permissive
[root@cali selinux]#
[root@cali selinux]# setenforce 1  
[root@cali selinux]# getenforce  
Enforcing
[root@cali selinux]#

·进程控制 :控制哪些进程能访问哪些文件,因为它对进程和文件进行了分类,制定了策略,策略里规定了哪些类型的进程能操作哪些类型的文件。

·服务异常不能访问–》通过网络不能访问
·1.考虑iptables防火墙是否开启
·2.考虑selinux安全机制是否开启

·iptables 是外层的安全策略防火墙
·selinux是linux内部的安全策略机制防火墙

博客链接:https://blog.csdn.net/yanjun821126/article/details/80828908

SELinux
是内核集成的一个安全相关的子系统,可以让系统更加的安全
内核版本2.6以上支持

#注:查看内核版本 uname -r
[root@sanchuang-linux bin]# uname -r
4.18.0-193.el8.x86_64

安全增强型 Linux(Security-Enhanced Linux)简称 SELinux,它是一个 Linux 内核模块,也是 Linux 的一个安全子系统。

SELinux 的作用
SELinux 主要作用就是最大限度地减小系统中服务进程可访问的资源(最小权限原则)。

DAC:
在没有使用 SELinux 的操作系统中,决定一个资源是否能被访问的因素是:某个资源是否拥有对应用户的权限(读、写、执行)
这种权限管理机制的主体是用户,也称为自主访问控制(DAC)

MAC:
在使用了 SELinux 的操作系统中,决定一个资源是否能被访问的因素除了上述因素之外,还需要判断每一类进程是否拥有对某一类资源的访问权限。
这种权限管理机制的主体是进程,也称为强制访问控制(MAC)

默认情况下SElinux属于关闭状态(disable) 服务访问不了基本是设置了SElinux

示例:临时修改

#注:临时修改 关机重启后失效
#注:临时配置,重新启动系统会失效
#注:0  --》Permissive 宽容模式
#注:1  --》Enforcing  强制执行模式
[root@sanchuang-linux ~]# getenforce 			# 注:获取当前selinux的模式
Disabled
[root@sanchuang-linux ~]# setenforce 0			# 注:0宽容模式		临时生效
setenforce: SELinux is disabled
[root@sanchuang-linux ~]# setenforce 1			# 注:1强制模式(一定要遵循SELinux规则)
setenforce: SELinux is disabled
#注:0|1  Permissive|Enforcing  宽容模式|强制执行模式

示例:永久生效 修改配置文件

#注:配置文件:/etc/selinux/config
[root@sanchuang-linux ~]# vim /etc/selinux/config
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled		# 注:指定工作模式
#注:修改之后生效,需要重启电脑
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mycpen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值