一、显示和设置selinux

[root@localhost ~]# vim /etc/sysconfig/selinux //强制模式 许可模式 禁用模式
[root@localhost ~]# getenforce //查看当前SElinux的状态
[root@localhost ~]# setenforce //可以在强制模式(1) 许可模式(0)之间切换
[root@localhost ~]# sestatus //列出目录SELinux使用的策略(Policy)

二、查看安全上下文

进程

ps -ZC sshd

文件

ll -dZ /var/www/html/

端口

[root@localhost ~]# yum provides *bin/semanage
[root@localhost ~]# semanage port -l |egrep '\<80\>'
http_port_t tcp 80, 443, 488, 8008, 8009,
8443

三、修改selinux 上下文

cp 、 mv 对上下文影像

cp:会重新生成安全上下文

mv:安全上下文则不变

Chcon:

1、  chcon –R httpd_sys_content_t 
/webdata

2、  chcon –R –reference /var/www/html  
/webdata     //将前一个文件的上下文作为参考,赋给/webdata

例:ftp匿名上传

  1. 文件系统的权限
    [root@localhost ~]# mkdir /var/ftp/music
    [root@localhost ~]# setfacl -m u:ftp:rwx /var/ftp/music/
    2. FTP服务器配置
    anonymous_enable=YES
    anon_upload_enable=YES
    anon_mkdir_write_enable=YES

修改上下文

chcon –R  public_content_rw_t
 /var/ftp/music/

3.查看

[root@localhost ~]# getsebool -a | grep
ftpd

4.设置

[root@localhost ~]# setsebool -P allow_ftpd_anon_write on

5.启动

[root@localhost ~]# systemctl
start vsftpd

四、监控selinux策略冲突情况

部署selinux日志分析工具

1、安装setroubleshoot-server软件包,才能将SELinux消息发送至/var/log/messages

setroubleshoot-server侦听/var/log/audit/audit.log中的审核信息并将简短摘要发送至/var/log/messages
该摘要包括SELinux冲突的唯一标识符(UUIDs),可用于收集更多信息

2、systemctl  restart  rsyslog

Systemctl  restart  auditd

3、测试

[root@localhost ~]# vim /tmp/index.html

[root@localhost ~]# mv /tmp/index.html
/var/www/html/

[root@localhost ~]# curl http://localhost

<!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 /index.html                 //权限拒绝,不能访问

on this server.</p>

</body></html>

4、查看/var/log/messages

Nov 16 02:03:35 localhost setroubleshoot:
SELinux is preventing httpd from open access on the file
/var/www/html/index.html. For complete SELinux messages run: sealert
-l f1243e54-7eb7-458b-a260-ca1f8ff61070

……………………………………………………..

If you want to fix the label.

/var/www/html/index.html default label
should be httpd_sys_content_t.

Then you can run restorecon.

Do

# /sbin/restorecon -v
/var/www/html/index.html

………………..

[root@localhost ~]# /sbin/restorecon -v
/var/www/html/index.html

/sbin/restorecon reset
/var/www/html/index.html context
unconfined_u:object_r:user_tmp_t:s0->unconfined_u:object_r:httpd_sys_content_t:s0

5、访问成功

[root@localhost ~]# curl http://localhost

------------------------------

this is a test web !

selinux-网络服务安全的更多相关文章

  1. [转载]SELinux 环境下网络服务设置,配置 Apache 、Samba、NFS

    原文地址:http://www.ibm.com/developerworks/cn/linux/l-cn-selinux-services1/index.html?ca=drs- 引言 SELinux ...

  2. Salesforce Apex页面中调用远端网络服务

    本文介绍了Salesforce Apex页面中调用远端网络服务的实现过程. ### 注册远端网络服务 在使用Apex代码调用远端网络服务之前,首先需要在Salesforce中注册远端网络服务地址, 本 ...

  3. 1、linux网络服务实验 用PuTTY连接Linux

    这个是大三下学期的Linux网络服务配置详解时,感觉老师上得简单,就整理下,岭南师范学院师弟妹有福,如果是蔡老师交的话,可以拿来预习,复习. 一.用PuTTY连接Linux ①.装有redhat系统的 ...

  4. /etc/xinetd.conf 和 /etc/xinetd.d/*【新网络服务配置】

    http://blog.csdn.net/kelven2004/article/details/1701930 xinetd 是 inetd 的安全加强版,它内置了自己的 TCP wrapper, 可 ...

  5. 在docker里部署网络服务

    之前试着玩玩docker有一阵子了,今天算是头一回正式在docker里部署网络服务. 本来想和lxc差不多的东西那自然是手到擒来,没想到还是改了很多. 第一个遇到的问题是,远程连到docker宿主机干 ...

  6. Nodejs·网络服务

    本章是从NodeJS拥有的模块角度,讲述了网络服务中的应用: net ----- > TCP dgram --> UDP http -----> HTTP https ----> ...

  7. linux配置oracle11G监听及本地网络服务 及 数据库建库

    配置监听及本地网络服务 在oracle用户的图形界面oracle用户中,新开启一个终端,输入命令netca 会弹出如下界面. 数据库建库 在oracle用户的图形界面oracle用户中,新开启一个终端 ...

  8. Oracle配置本地网络服务名

    Oracle安装完成后,可以使用客户端自带的的网络配置向导(Net Configuration Assistant)进行配置 1.启动Net Configuration Assistant.选择&qu ...

  9. ubuntu 12.04 "系统的网络服务与此版本的网络管理器不兼容

    ubuntu 12.04 "系统的网络服务与此版本的网络管理器不兼容“ 2013-05-10 21:18 2271人阅读 评论(0) 收藏 举报 今天上午在实验室一顿乱整,不知道整坏了什么, ...

  10. jmeter 建立一个网络服务的测试计划

    如何创建一个 测试计划 测试一个网络服务. 你会 创建5个用户发送请求到一页. 同时,你会告诉用户运行测试两次. 的总数 请求用户请求(5)x(1)x(重复2次)= 10 HTTP请求. 来 建立测试 ...

随机推荐

  1. Easy UI分页控件修改刷新方法后触发两次请求

    今天我在做分页的时候,有这样的一个现象: 我重写了分页的刷新和改变页面大小的方法,发现给服务器提交了两次post,问题出现在哪里的?经过alert调试,发现原因是: 刷新和改变页面大小的事件执行的时候 ...

  2. Golang 中操作 Mongo Update 的方法

    Golang 和 MongoDB 中的 ISODate 时间交互问题 2018年02月27日 11:28:43 独一无二的小个性 阅读数:357 标签: GolangMongoDB时间交互时间转换 更 ...

  3. koa介绍

    https://github.com/koajs/koa https://github.com/demopark/koa-docs-Zh-CN ctx.response.type = 'json'; ...

  4. Ci 错误 In order to use the Session class you are required to set an encryption key in your config file.

    说明自己没有给session 加密  ,在配置文件config中     $config['encryption_key'] = '2rf3f3fwefwefwef2';

  5. 关于Unity中的transform组件(三)

    game_root节点下右一个Cube子节点,和一个Sphere节点,脚本挂载在game_root下 四元数:(1)Quaternion rot (2)this.cube.rotation 欧拉角:V ...

  6. ubuntu14.04中安装jdk

    1. 下载JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 将下载的 .g ...

  7. 嵌入式驱动开发之采集方式bypass mode---bypass mode

    http://baike.baidu.com/link?url=HifFTlNRROR24lW_gSdTiG-eXooi08O0Eeq1mU6Yy0I1LOMW4kdumv25BOQbohV_428M ...

  8. php -- php检测文件编码的方法示例

    <?php /** * 检测文件编码 * @param string $file 文件路径 * @return string|null 返回 编码名 或 null */ function det ...

  9. Java Print 打印

    Java 原生的API中有Print,使用Print可以操作打印机进行打印操作,获取打印机属性,下面是代码 打印程序(静默打印) package com.boci.PrintPDF; import j ...

  10. 杭电 1280 前m大的数

    http://acm.hdu.edu.cn/showproblem.php?pid=1280 前m大的数 Time Limit: 2000/1000 MS (Java/Others)    Memor ...