电脑疯子技术论坛|电脑极客社区

微信扫一扫 分享朋友圈

已有 2114 人浏览分享

Linux查看、修改SELinux的状态

[复制链接]
2114 0

SELinux(Security-Enhanced Linux) 是美国国家安全局(NSA)对于强制访问控制的实现,是 linux历史上最杰出的新安全子系统。
但是我们一般都不用它,因为它管的东西太多了,想做安全可以用防火墙等其他措施。
我们可以通过查看配置文件的命令 cat /etc/selinux/config 来查看状态,

  1. [root@mazhonghua ~]# cat /etc/selinux/config
  2. [root@mazhonghua ~]# cat /etc/selinux/config
  3. # This file controls the state of SELinux on the system.
  4. # SELINUX= can take one of these three values:
  5. #     enforcing - SELinux security policy is enforced.
  6. #     permissive - SELinux prints warnings instead of enforcing.
  7. #     disabled - No SELinux policy is loaded.
  8. SELINUX=enforcing
  9. # SELINUXTYPE= can take one of these two values:
  10. #     targeted - Targeted processes are protected,
  11. #     mls - Multi Level Security protection.
  12. SELINUXTYPE=targeted
复制代码


发现SELinux共有3个状态enforcing (执行中)、permissive (不执行但产生警告)、disabled(关闭)。
  我们可以通过修改配置文件来修改SELinux的状态

  1. [root@mazhonghua ~]# sed -i s#SELINUX=enforcing#SELINUX=disabled# /etc/selinux/config
  2. [root@mazhonghua ~]# cat /etc/selinux/config

  3. # This file controls the state of SELinux on the system.
  4. # SELINUX= can take one of these three values:
  5. #     enforcing - SELinux security policy is enforced.
  6. #     permissive - SELinux prints warnings instead of enforcing.
  7. #     disabled - No SELinux policy is loaded.
  8. SELINUX=disabled
  9. # SELINUXTYPE= can take one of these two values:
  10. #     targeted - Targeted processes are protected,
  11. #     mls - Multi Level Security protection.
  12. SELINUXTYPE=targeted
复制代码


最后我们重启服务器,SELinux状态由enforcing变为disabled 。  当然,一般我们的Linux都不能重启,
我们可以使用这个命令 setenforce 1 临时(重启即失效)设置SELinux 成为enforcing模式
(setenforce 0 设置SELinux 成为permissive模式),用getenforce这个命令来检查。

  1. root@mazhonghua ~]# setenforce 0
  2. [root@mazhonghua ~]# getenforce
  3. Permissive
复制代码


我们还可以用 /usr/sbin/sestatus 命令来查看SELinux的状态。

  1. [root@mazhonghua ~]# /usr/sbin/sestatus
  2. SELinux status:                 enabled
  3. SELinuxfs mount:                /selinux
  4. Current mode:                   enforcing
  5. Mode from config file:          disabled
  6. Policy version:                 24
  7. Policy from config file:        targeted
复制代码





您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

关注

0

粉丝

9021

主题
精彩推荐
热门资讯
网友晒图
图文推荐

Powered by Pcgho! X3.4

© 2008-2022 Pcgho Inc.