问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

如何解决SELinux问题

发布网友 发布时间:2022-04-25 13:14

我来回答

5个回答

懂视网 时间:2022-04-12 14:18

When you create the linux file node, such as “dev/nfccard0”, you must add the selinux policy for it, or the application can not get the permit to access. this is an example for the system_server to accecc the dev/nfccard0 file node. we c

When you create the linux file node, such as “dev/nfccard0”, you must add the selinux policy for it, or the application can not get the permit to access.

this is an example for the system_server to accecc the dev/nfccard0 file node.

we can do the following three things to mak the system work smoothly.

1 define the file type

in the file.te add the below line

type nfccard_device,dev_type

2 define the file context

in the file_context.te add the below line

/dev/nfccard0 u:object_r:nfccard_devicd:s0

3 allow the system_server to access it.

Allow system_server nfccard_device:chr_file rw_file_perms

Or

Allow system_server nfccard_device:chr_file {read write open getattr ioctl}

there are many file type , {socket, binder, property,etc}, we must do carefully to avoid influence the system.

热心网友 时间:2022-04-12 11:26

  首先需要确认SELinux处于激活状态,可以使用getenforce命令:
  shell> getenforce
Enforcing

  或者使用sestatus命令:
  shell> sestatus
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 24
Policy from config file: targeted

  注:关于SELinux的基础知识介绍请参考鸟哥的Linux私房菜中相关的介绍。
  我们还需要确认系统已经安装并启动了Apache,没有的话就YUM装一个,这很简单,就不多说了,接着在root目录创建一个测试文件test.html,如下:
  shell> cat /root/test.html
hello, world.

  然后把这个测试文件拷贝到Apache的DocumentRoot目录,我的Apache是通过YUM安装的话,缺省是/var/www/html目录,如下:
  shell> cp /root/test.html /var/www/html

  接着浏览一下,如果没出什么幺蛾子,应该一切都在意料之中,如下:
  shell> curl http://localhost/test.html
hello, world.

  看到这,你可能觉得我废话连篇,别着急,下面就是见证奇迹的时候了:
  同样还是那个测试文件test.html,不过这次不再是拷贝,而是移动,如下:
  shell> mv /root/test.html /var/www/html

  接着浏览一下,怎么样,结果很出人意料吧,竟然提示权限错误,如下:
  shell> curl http://localhost/test.html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /test.html
on this server.</p>
</body></html>

  当然,我们现在知道这个问题是由于SELinux引起的,但还不知其所以然,实际上问题的原因此时已经被audit进程记录到了相应的日志里,可以这样查看:
  shell> audit2why < /var/log/audit/audit.log

  如果看不懂的话,推荐安装setroubleshoot套件:
  shell> yum install setroubleshoot

  它本身是一个GUI套件,不过其中包含的一个sealert命令对我们命令行用户很有用:
  shell> sealert -a /var/log/audit/audit.log
Summary:

SELinux is preventing /usr/sbin/httpd "getattr" access to
/var/www/html/test.html.

Detailed Description:

SELinux denied access requested by httpd. /var/www/html/test.html may be a
mislabeled. /var/www/html/test.html default SELinux type is httpd_sys_content_t,
but its current type is admin_home_t. Changing this file back to the default
type, may fix your problem.

File contexts can be assigned to a file in the following ways.

* Files created in a directory receive the file context of the parent
directory by default.
* The SELinux policy might override the default label inherited from the
parent directory by specifying a process running in context A which creates
a file in a directory labeled B will instead create the file with label C.
An example of this would be the dhcp client running with the dhclient_t type
and creating a file in the directory /etc. This file would normally receive
the etc_t type e to parental inheritance but instead the file is labeled
with the net_conf_t type because the SELinux policy specifies this.
* Users can change the file context on a file using tools such as chcon, or
restorecon.

This file could have been mislabeled either by user error, or if an normally
confined application was run under the wrong domain.

However, this might also indicate a bug in SELinux because the file should not
have been labeled with this type.

If you believe this is a bug, please file a bug report against this package.

Allowing Access:

You can restore the default system context to this file by executing the
restorecon command. restorecon '/var/www/html/test.html', if this file is a
directory, you can recursively restore using restorecon -R
'/var/www/html/test.html'.

Fix Command:

/sbin/restorecon '/var/www/html/test.html'

  这次应该看懂了吧!原因是说Apache下文件上下文类型应该是httpd_sys_content_t,但是现在是admin_home_t,所以权限错误,并且在结尾处给出了修复命令。
  可httpd_sys_content_t,admin_home_t都怎么看啊?很简单,借助ls命令的-Z参数即可:
  shell> ls -Z /path

  回到问题的开始,拷贝之所以没出现问题,是因为cp自动修改上下文属性,而移动之所以出现问题是因为mv保留原文件的上下文属性。
  注:关于SELinux和Apache的详细介绍,可以参考『man httpd_selinux』。
  知道了如何解决SELinux问题,以后如果遇到类似的情况不要急着武断的关闭SELinux。

热心网友 时间:2022-04-12 12:44

有碰到即使是permissive也不行的,最后是改成disabled后重启机器才可以。

热心网友 时间:2022-04-12 14:19

上面有个小错,应该是echo "0" > /selinux/enforce (少了>)selinux如果有开很容易造成ifind问题,参看下面系统日志Aug 2 20:52:06 cc-lnx-imglib setroubleshoot: SELinux is preventing /opt/simpana/iDataAgent/ifind "execstack" access to . For complete SELinux messages. run sealert -l 4a0b3993-b18f-4c72-9e1d-4f5d8175ad41Jul 31 00:30:09 cc-lnx-imglib setroubleshoot: SELinux is preventing /bin/hostname access to a leaked /tmp/.gxsetup/cvpkglo g.pipe.26262 file descriptor. For complete SELinux messages. run sealert -l e675a6a6-efc9-461f-b794-784c0fd2d308

热心网友 时间:2022-04-12 16:10

别一种查看SElinux方法:# sestatusSELinux status: disabled
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
哪种颜色款式的拉丁舞服装好看 初学拉丁舞穿裤还是裙 有时 有时 有时造句 诺基亚n73手机地图2008年新版的在哪可以下? 我用n73上网,怎么样可以下载地图包 NOKIA N73手机地图问题 脖子里面长了个硬疙瘩 开始有点硬。 不发红。 现在中间有点红, 变软了。 周边有点硬 手相真的能看出一个人的命运吗 双色球蓝球明晚开什么 索道是什么呢 Ext.getCmp(&#39;cardIn&#39;).disable(&#39;true&#39;); 有效 Ext.getCmp(&#39;cardIn... 为什么我的DELL电脑重装后开机出现警报声,说找不到驱动,但按F1,又能... phalcon是有个bug的? 如何提高电脑开机速度~~ 求助Easyui datagrid 的默认选中问题 【简单】改一句代码就行 easyui datagrid 怎样默认为全选数据 谁帮我翻译一下这段英文?电脑方面的 jquery如何获取整个页面文本框属性为disabled的id ,并用循环遍历出内容... WebDriver到底怎么用 写一个HTML页面,实现以下功能 如何在javascript中让一个链接变成灰色,不可点击? 如何启动cookie(转)How to Enable Cookies 开机后屏幕显示“alert! Cover was prviously removed”,什么意思... 2018年江苏省盐城市、南京市高考英语二模试卷 含解析 全国高考二卷是哪些省市专考的? 2018年高考英语分不分乙、甲、丙卷 直播伴侣可以推流到视频号嘛 2018年高考试题及答案(全国2卷、全国二卷)(英语)(高清) 索道 什么意思 谁能用简单文字 详细解释 谢谢你 谁给 个easyui里面datagrid的例子,用json加载 的例子 如何让外观专利无效 什么是索道?为什么爬山时有人走索道??? dell 服务器开机报错 外观专利无效的条件 索道和缆车的区别是什么?? 如何调出OneThink的ueditor编辑器 索道和缆车的区别是什么? 什么情况下外观专利无效 jquery easyui怎么动态改treegrid表上的toolbar的按钮的样式和文字... 太白山索道是什么? 如何申请专利专利宣告专利无效 什么是索道运输,有什么技术要求? 无效外观专利需要什么证据 缆车与索道有什么区别? 怎样认定外观设计专利的无效 “华山西峰索道”的简介是什么? 怎么申请对方专利无效 八大处索道是什么?滑道是什么?都多少钱?学生能打折吗?