当前位置: 代码网 > 服务器>服务器>Linux > Linux中如何开启或关闭SELinux

Linux中如何开启或关闭SELinux

2024年05月18日 Linux 我要评论
selinux是什么安全增强型linux(selinux)是一个linux内核的功能,它提供支持访问控制的安全政策保护机制。开启selinux1.以root权限远程连接linux2.编辑selinux

selinux是什么

安全增强型linux(selinux)是一个linux内核的功能,它提供支持访问控制的安全政策保护机制。

开启selinux

1.以root权限远程连接linux

2.编辑selinux的config文件。

vim /etc/selinux/config

3.找到selinux=disabled,按i进入编辑模式,通过修改该参数开启selinux。

可以根据需求修改参数,开启selinux有以下两种模式:

  • 强制模式selinux=enforcing:表示所有违反安全策略的行为都将被禁止。
  • 宽容模式selinux=permissive:表示所有违反安全策略的行为不被禁止,但是会在日志中作记录。

4.修改完成后,按下键盘esc键,执行命令:wq,保存并退出文件。

5.在根目录下新建隐藏文件autorelabel,实例重启后,selinux会自动重新标记所有系统文件。

touch /.autorelabel

6.重启linux

shutdown -r now

验证selinux状态

1.以root权限远程连接ecs实例。连接方式请参见连接方式概述。运行命令getenforce,验证selinux状态。

2.返回状态应为enforcing或者permissive,本教程当前状态为enforcing。

3.运行命令sestatus,获取更多selinux信息。

参数信息selinux status显示为enabled,表示selinux已启动。

关闭selinux

1.以root权限远程连接ecs实例。连接方式请参见连接方式概述。

2.运行命令getenforce,验证selinux状态。返回状态如果是enforcing,表明selinux已开启。

3.选择临时关闭或者永久关闭selinux。

  • 执行命令setenforce 0临时关闭selinux。
  • 永久关闭selinux。

a.运行以下命令,编辑selinux的config文件。vim /etc/selinux/config

b.找到selinux=enforcing,按i进入编辑模式,将参数修改为selinux=disabled。

[root@ncayu101 data]# getenforce
enforcing

# 临时关闭 selinux
[root@ncayu101 data]# setenforce 0
[root@ncayu101 data]# 
[root@ncayu101 data]# 
[root@ncayu101 data]# getenforce
permissive
# this file controls the state of selinux on the system.
# selinux= can take one of these three values:
#     enforcing - selinux security policy is enforced.
#     permissive - selinux prints warnings instead of enforcing.
#     disabled - no selinux policy is loaded.
selinux=enforcing
# selinuxtype= can take one of three values:
#     targeted - targeted processes are protected,
#     minimum - modification of targeted policy. only selected processes are protected. 
#     mls - multi level security protection.
selinuxtype=targeted

我已经修改好了

  • 修改完成后,按下键盘esc键,执行命令:wq,保存并退出文件。
  • 运行命令getenforce,验证selinux状态为disabled,表明selinux已关闭。

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com