您的位置:首页 > 运维架构 > Linux

Linux下开启关闭SeLinux

2015-07-08 22:01 615 查看
SELinux(Security-EnhancedLinux)inFedoraisanimplementationofmandatoryaccesscontrolintheLinuxkernelusingtheLinuxSecurityModules(LSM)framework.StandardLinuxsecurityisadiscretionaryaccesscontrolmodel.Discretionaryaccesscontrol(DAC)DACisstandardLinuxsecurity,anditprovidesminimalprotectionfrombrokensoftwareormalwarerunningasanormaluserorroot.Userscangrantriskylevelsofaccesstofilestheyown.Mandatoryaccesscontrol(MAC)MACprovidesfullcontroloverallinteractionsofsoftware.Administrativelydefinedpolicycloselycontrolsuserandprocessinteractionswiththesystem,andcanprovideprotectionfrombrokensoftwareormalwarerunningasanyuser.目前SELinux支持三种模式,分别如下:enforcing:强制模式,代表SELinux运作中,且已经正确的开始限制domain/type了;permissive:宽容模式:代表SELinux运作中,不过仅会有警告讯息并不会实际限制domain/type的存取。这种模式可以用来作为SELinux的debug之用;disabled:关闭,SELinux并没有实际运作在Linux下查看是否开启了SeLinux,可以用下面两种方法1:可以使用下面命令sestatus,SELinuxstatus为enabled表示开启了SeLinux功能

[root@DB-Server~]#/usr/sbin/sestatus
SELinuxstatus:enabled
SELinuxfsmount:/selinux
Currentmode:enforcing
Modefromconfigfile:enforcing
Policyversion:21
Policyfromconfigfile:targeted
[root@DB-Server~]#
[root@DB-Server~]#/usr/sbin/sestatus-v
SELinuxstatus:enabled
SELinuxfsmount:/selinux
Currentmode:enforcing
Modefromconfigfile:enforcing
Policyversion:21
Policyfromconfigfile:targeted
Processcontexts:
Currentcontext:root:system_r:unconfined_t:SystemLow-SystemHigh
Initcontext:system_u:system_r:init_t
/sbin/mingettysystem_u:system_r:getty_t
/usr/sbin/sshdsystem_u:system_r:unconfined_t:SystemLow-SystemHigh
Filecontexts:
Controllingterm:root:object_r:devpts_t
/etc/passwdsystem_u:object_r:etc_t
/etc/shadowsystem_u:object_r:shadow_t
/bin/bashsystem_u:object_r:shell_exec_t
/bin/loginsystem_u:object_r:login_exec_t
/bin/shsystem_u:object_r:bin_t->system_u:object_r:shell_exec_t
/sbin/agettysystem_u:object_r:getty_exec_t
/sbin/initsystem_u:object_r:init_exec_t
/sbin/mingettysystem_u:object_r:getty_exec_t
/usr/sbin/sshdsystem_u:object_r:sshd_exec_t
/lib/libc.so.6system_u:object_r:lib_t->system_u:object_r:lib_t
/lib/ld-linux.so.2system_u:object_r:lib_t->system_u:object_r:ld_so_t
Youhavenewmailin/var/spool/mail/root
[root@DB-Server~]#




2:使用命令getenforce

[root@DB-Server~]#getenforce
Enforcing


如何开启、关闭SeLinux呢?最简单的方式使用setenforce,这样不用重启服务器.但是该命令只能将SeLinux在enforcing、permissive这两种模式之间切换.服务器重启后,又会恢复到/etc/selinux/config下,也就是说setenforce的修改是不能持久的。

[root@DB-Server~]#setenforce0
[root@DB-Server~]#getenforce
Permissive
[root@DB-Server~]#setenforce1
[root@DB-Server~]#getenforce;
Enforcing
[root@DB-Server~]#

另外就是修改/etc/selinux/config,如下所示,可以配置SELINUX为enforcing、permissive、disabled三个值,修改后必须重启系统才能生效

[root@DB-Server~]#more/etc/selinux/config
#ThisfilecontrolsthestateofSELinuxonthesystem.
#SELINUX=cantakeoneofthesethreevalues:
#enforcing-SELinuxsecuritypolicyisenforced.
#permissive-SELinuxprintswarningsinsteadofenforcing.
#disabled-SELinuxisfullydisabled.
SELINUX=enforcing
#SELINUXTYPE=typeofpolicyinuse.Possiblevaluesare:
#targeted-Onlytargetednetworkdaemonsareprotected.
#strict-FullSELinuxprotection.
SELINUXTYPE=targeted
Youhavenewmailin/var/spool/mail/root
[root@DB-Server~]#

如果由enforcing或permissive改成disabled,或由disabled改成其他两个,那也必须要重新开机。这是因为SELinux是整合到核心里面去的,你只可以在SELinux运作下切换成为强制(enforcing)或宽容(permissive)模式,不能够直接关闭SELinux的!同时,由SELinux关闭(disable)的状态到开启的状态也需要重新开机啦!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: