怎么查看centos的selinux是否关闭

以下是禁用SELinux的方法。
系统版本:centos6.5mini1。
检查selinuxstatus查看详细的selinux状态。
如果亮起,则表示已开启。
#/usr/sbin/sestatus-v检查。
selinux模式#getenforce2。
禁用selinux2.1:永久关闭(重启服务器后生效)#sed-i's/SELINUX=enforcing/SELINUX=disabled/'/etc/selinux/config2.2:临时关闭(立即生效,之后无效服务器重新启动)#setenforce0#将selinux设置为宽容模式(即禁用)#setenforce1#将selinux设置为强制模式(即启用))这将禁用SELinux。
如果您在安装软件时遇到问题,可以禁用SELinux,然后再安装。

Linux开启或关闭SELinux

安全增强型Linux(SELinux)是Linux内核的一项功能,旨在为访问控制提供安全策略保护机制。
本文将指导您了解如何打开或关闭SELinux以及如何避免系统启动过程中出现问题。
以下是启用SELinux的步骤:1.首先在服务器上以管理员身份运行sudovi/etc/selinux/config命令打开配置文件。
2.您可以根据需要修改此文件中的参数。
开启SELinux有两种模式:强制模式和宽容模式。
在强制模式下,SELinux严格遵守安全策略,而在审核模式下,SELinux监视系统活动,但不会阻止不合规操作。
3.修改完成后,使用键盘快捷键Esc退出编辑模式,然后键入wq保存文件并退出。
4.重新启动系统,然后运行getenforce命令检查SELinux状态。
如果显示已禁用,则SELinux已关闭。
如果您在打开SELinux后遇到阻止系统启动的问题,请记住您的SELinux策略可能过于严格,这可能会阻止某些服务或应用程序正常运行。
此时,您可以将SELinux置于审核模式,允许系统运行,同时监视不合规的访问尝试。
开启审计模式后,可以查看SELinux日志文件(如/var/log/audit/audit.log)来分析问题,找到系统无法启动的具体原因,调整SELinux策略如下:你需要它。
最后,定期检查您的SELinux策略,以确保其满足您的安全要求,同时避免对系统操作造成不必要的限制。

selinux常用参数

了解并配置SELinux1。
获取当前SELinux运行时状态getenforce可以返回三种结果:正在运行、已启用和已禁用。
disabled表示禁用SELinux,permit表示仅记录安全警告,但不阻止可疑行为,enforce表示记录并阻止可疑行为。
现在常见的发行版中,RHEL、CentOS、Fedora等都是设置为默认执行,而openSUSE等其他发行版则设置为许可证。
2、改变SELinux运行模式setenforce[Enforcing|Permissive|1|0]该命令立即改变SELinux运行模式,在Enforcing和Permissive之间切换,效果一直保持到关机。
常见用途是查看SELinux是否阻止服务或程序运行。
如果setenforce0后服务或程序仍然无法运行,则绝对不是SELinux的原因。
如果你想永久改变系统的SELinux环境,可以通过修改配置文件/etc/selinux/config来实现。
请注意,从禁用模式更改为宽容或强制模式时,必须重新启动计算机并重新创建整个文件系统的安全标签(touch/.autorelabel&&reboot)。
[root@web2~]#vim/etc/selinux/config#该文件控制selinux系统状态。
ecuritypolicysenforced.#enforced-SELinuxprintswarning.#disabled-NoSELinuxpolicyisloaded.SELINUX=enforce#SELINUXTYPE=可以采用以下值之一:#target-scheduledprocessisprotected,#mls-MultiLevelSecurityprotection.SELINUXTYPE=target3.SELinux运行策略配置文件/etc/selinux/config也是SELinux包含操作策略信息,可以通过改变变量SELINUXTYPE的值来获取,该值有两个选项:Target表示SELinux保护仅用于一些预定义的网络服务和访问请求。
而严格意味着所有网络服务和访问请求都经过SELinux。
针对RHEL、CentOS、Fedora等的默认设置是有针对性的,其中包括几乎所有常见网络服务的SELinux策略配置。
如果想要手动编辑SELinux策略,还提供了命令行下的策略编辑器edit和Eclipse下的编辑插件eclipse-slide。
4、SELinux模式coreutils工具,如ps、ls等,可以通过添加Z选项来访问SELinux信息。
要获得4.1,请使用ps:[barlow@web1~]$ps-auxZ|grephttpd|head-5warning:badsyntax,possible'-'?see/usr/share/doc/procps-3.2.8/FAQunconfined_u:system_r:httpd_t:s0apache13930.00.22796482272?SJun270:01/usr/sbin/httpdunconfined_u:system_r:httpd_t:s0apache13950.01.527296415528?SJun270:02/usr/sbin/httpdunconfined_u:system_r:httpd_t:s0apache13990.01.727296417828?SJun270:02/usr/sbinn/httpdunconfined_u:system_r:httpd_t:s0apache14050.01.227296412732?SJun270:02/usr/sbin/httpdunconfined_u:system_r:httpd_t:使用s0apache14090.01.427296814784?SJun270:03/usr/sbin/httpd4.2[barlow@web1~]$ls-Z/var/www/drwxrwxrwx.apachebarlowunconf获取ned_u:object_r:httpd_sys_script_exec_t:s0cgi-bindrwxrwxrwx.apachebarlounconfined_u:object_r:httpd_sys_content_t:s0errordrwxrwxrwx.apachebarlowunconfined_u:object_r:httpd_sys_content_t:s0htmldrwxrwxrwx.apachebarlounconfined_u:object_r:httpd_syss_content_t:s0iconsdrwxrwxrwx.apachebarlowsystem_u:object_r:httpd_sys_content_t:s0lost+found等Z选项可以应用于所有coreutils工具。
5、修改与httpd服务相关的SELinux策略的常用方法:如上所述,ls-Z方法请求的文件的SELinux上下文与默认条件不匹配,导致服务无法正常使用。
SELinux需要一个网址或httpd服务文件httpd_sys_content_t,否则客户端无法访问它。
5.1使用chcon修改httpd目录或文件安全上下文,例如nagios服务器的web目录上下文默认为unconfined_u:object_r:usr_t:s0,客户端无法访问:[root@nagios~]#ll-Z/usr/local/nagios/share/-rwxrwxr-x.nagiosapachesystem_u:object_r:usr_t:s0config:usr_t:s0imagesdrwxrwxr-x.nagiosapacheunconfined_u:object_r:usr_t:s0contained-rwxrwxr-x.nagiosapachesystem_u:object_r:usr_t:s0index.html-rwxrwxr-x.nagiosapachesystem_u:object_r:usr_t:s0index.php...如下完成...使用chcon更改/usr/local/nagios/share/目录及其下的所有文件。
object_r:httpd_sys_content_t[root@nagios~]#chcon-Runconfined_u:object_r:httpd_sys_content_t:s0/usr/local/nagios/share/查询结果:[root@nagios~]#ls-Z/usr/local/nagios/sh是/-rwxrwxr-x.nagiosapacheunconfined_u:object_r:httpd_sys_content_t:s0config.inc.phpdrwxrwxr-x.nagiosapacheunconfined_u:object_r:httpd_sys_content_t:s0contexthelpdrwxrwxr-x.nagiosapacheunconfined_u:object_r:httpd_sys_content_t:s0docsdrwxrwxr-x.nagiosapacheunconfined_u:object_r:httpd_sys_content_t:s0imagesdrwxrwxr-x.nagiosapacheunconfined_u:object_r:httpd_sys_content_t:s0imagesdrwxrwxr-x.nagiosapacheunconfined_u:对象_r:httpd_sys_content_t:s0index.html-rwxrwxr-x.nagiosapacheunconfined_u:object_r:httpd_sys_content_t:s0index.phpdrwxrwxr-x.nagiosapacheunconfinedned_u:object_r:httpd_sys_content_t:s0locale-rwxrwxr-x.nagiosapacheunconfined_u:object_r:httpd_sys_content_t:s0main.html客户端无需重启httpd服务即可访问。
5.2使用seminar工具支持httpd的非标准端口:forward工具非常强大,基本上可以实现所有的SELinux配置,但往往我们不知道SELinux错误出在哪里。
图形界面下,以及终端界面中还有一个非常强大的分析工具sealert,但是默认情况下,这两个工具都没有安装。
首先需要安装seminage和打印工具:[root@web2~]#yum-yinstallpolicycoreutils-pythonsettroubleshoot注:关于系统使用,也可以看我的另一篇博文:Selinux管理工具。
教育。
默认情况下,Apache仅侦听少数端口,例如80和443。
从您指定直接侦听端口808的服务启动httpdrestart时会报告错误。
Denied:mac_sock:Unabletobindaddress0.0.0.0:808nolistingsocketsavailable,shutdownUnabletoopenlogs[failure]检查/var/log/messages文件,看到以下错误您可以:[root@web2~]#tail/var/log/messagesJun2910:30:51web2settroubleshoot:SELinuxispreventing/usr/sbin_bihttpdfromfromfromfromndaccessonthetcp_socket.tocompleteSELinuxmessages.runsealert-l2ad073a4-7c64-4175-93ff-9d78f75133af按照提示。
sealert-l2ad073a4-7c64-4175-93ff-9d78f75133af将SELinux报告运行为:[root@web2~]#sealert-l2ad073a4-7c64-4175-93ff-9d78f75133af#semanageport-a-tPORT_TYPE-ptcp808PORT_TYPE以下之一:其中:ntop_port_t、http_cache_port_t、http_port_t、puppet_port_t、saging_port_t按照提示操作并运行semanageport-a-tPORT_TYPE-ptcp808。
输出:[root@web2~]#semanageport-l|grephttphttp_cache_port_ttcp3128,8080,8118,8123,10001-10010http_cache_port_tudp3130http_port_ttcp808,80,443,488,8008,8009,8443##可以看到端口808pegasus_http_port_ttcp5988pegasus_https_port_ttcp5989重新启动服务:[root@web2~]#servicehttpdstartisrunninghttpd:[OK]5.3更改selinux布尔值以允许创建私人网站您必须允许用户通过将文件放置在~/www/中来创建自己的网站手术将会完成。
使用:[root@web2~]#setseboolhttpd_enable_homedirs1默认情况下,setsebool设置仅保留到下次重新启动为止。
如果您希望它们永久应用,可以使用-P参数,例如:[root@web2~]#setsebool-Phttpd_enable_homedirs1setsebool用于更改由布尔值控制的SELinux策略。
请参阅与httpd关联的布尔值:[root@web2〜]#getSebool-a|grephtpallow_httplolaly_httpd_anon_write->offallow_htttpd_auth_mod_mod_ntlm_winbind-_winbind-_network_connect->offhttpd_can_network_connect_cobbler->offhttpd_can_network_connect_db->onhttpd_can_network_memcache->offhttpd_can_network_relay-->offhttpd_can_sendmail->offhttpd_dbus_avahi->onhttpd_enable_cgi->onhttpd_enable_ftp_server->offhttpd_enable_homedirs->onhttpd_execmem->on->offhttpd_manage_ipa->on关闭httpd_read_user_content->offhttpd_run_stickshift->offhttpd_setrlimit->offhttpd_ssi_exec->offhttpd_tmp_exec->offhttpd_tty_comm->在httpd_unified->在httpd_use_cifs->offhttpd_use_gpg->offhttpd_use_nfs->在httpd_use_openstack->Offhttpd_verify_dns->Offnamed_bind_http_port->上面列出了关闭