检查SELinux是否已经启用.

[root@localhost ~]# sestatus
SELinux status:  disabled

常用命令如下:

sestatus

查询系统的selinux目 前的狀态

selinuxenabled

查询系统的selinux支 援是否有启用

setenforce

设定selinux运 作狀态

getsebool

列出所有selinux bool数值清单列表与内容

setsebool

设定selinux bool数值内容

chcon

变更档案目录security context

restorecon

恢復档案目录的预设的security context

fixfiles

修正档案目录的预设的security context

semanage

SELiux policy管理程式

secon

检视行程、档案等等项目的SELinux context

audit2why

检视SELinux audit讯息内容

sealert

SELinux 讯息诊断用户端程式

下面列出几个常用的:

1、sestatus工具
查询系统的selinux 目前的状态
例如:root@monitor:~# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   permissive
Mode from config file:          permissive
Policy version:                 21
Policy from config file:        targeted

2、selinuxenabled工具
检查系统selinux是否开启,是通过返回值进行判断selinux是否已经启动,0:表示已经启动selinux;1:表示已经关闭selinux
例如:selinuxenabled ; echo?,返回的结果为:1

3、setenforce工具
功能:设定切换selinux的运行状态(0或者1),前提是开启了selinux,同时这种切换只对当前有效,如果重新启动的话,就没有效了(注意:如果关闭了selinux,那么就必须配置/etc/selinux/config文件)
语法:setenforce [ Enforcing | Permissive | 1 | 0 ]
说明如下:
enforcing 或者1,表示开启强制模式
permissive 或者0,表示开启警告但是无限制模式
例如:下面这个例子
root@monitor:~# sestatus | grep -i mod
Current mode:                   permissive
Mode from config file:          permissive
root@monitor:~# setenforce 1
root@monitor:~# sestatus | grep -i mod
Current mode:                   enforcing
Mode from config file:          permissive

4、getsebool与setsebool工具

说明:SELinux规范了许多boolean数值清单档案,提供开启或关闭功能存取项目,而这些值都存放在/selinux/booleans/目录内相关档案,这些档案里的值只有两种:1(启用)或 0(关闭)

1)getsebool
说明:列出所有selinux bool数值清单列表与内容
使用方式:getsebool [ -a ]
例如以下范例:
#getsebool ftpd_disable_trans
ftpd_disable_trans --> off
#getsebool -a
NetworkManager_disable_trans --> off
allow_cvs_read_shadow --> off
allow_daemons_dump_core --> on
allow_daemons_use_tty --> off
allow_execheap --> off
allow_execmem --> on
allow_execmod --> off
..........

2)setsebool
说明:设定selinux bool数值清单列表与内容
使用方式:setsebool [ -P ]  boolean value | bool1=val1 bool2=val2 bool3=val3......
参数配置: -P表示设定该项目永久套用
使用范例:
setsebool ftpd_disable_trans=on ( on 或者 1 )
setsebool -P ftpd_disable_trans=off ( off 或者 0 )

5、chcon
说明:变更档案目录的security context
使用方式:
chcon [OPTION]... CONTEXT FILE...
chcon [OPTION]... --reference=RFILE FILE...
参数如下:
-u USER:set user USER in the target security context
-r ROLE:set role ROLE in the target security context
-t TYPE:set type TYPE in the target security context
范例:
chcon -t var_t /etc/vsftpd/vsftpd.conf
chcon --reference=/var/www/html index.html
注意事项:若是变更于目录上,后续于该目录内建立的档案目录会套用目录本身type设定

6、restorecon
说明:恢复档案目录的预设的security Context
规格来源:/etc/selinux/<POLICY>/contexts/files/目录内的file_contexts与file_contexts.local
常用参数如下:
-r | -R:包含子目录与其下档案目录
-F:恢復使用预设的項目(就算是檔案符合存取规范)
-v:显示执行过程
使用方式:restorecon [FRrv] [-e excludedir ] pathname... ]
使用范例如下:
restorecon /etc/ntp.conf
restorecon -v /etc/ntp.conf
restorecon -v -F /etc/ntp.conf
手动配置新增恢复规则
1)档案名称
/etc/selinux/<POLICYTYPE>/contexts/files/file_contexts.local
2)新增配置范例
/var/ftp(/.*)?   system_u:object_r:public_content_t
3)注意
可以使用semanage程式来维护会比较方便

7、fixfiles
说明:修正档案目录的预设的security Context,依据/etc/selinux/<POLICY>/contexts/files/内相关档案修正
使用方式:
fixfiles { check | restore|[-F] relabel } [[dir] ... ]
fixfiles -R rpmpackage[,rpmpackage...] { check | restore }
参数:
-R:使用指定的rpm 套件所提供的檔案清單
使用范例:
fixfiles check /etc
fixfiles restore /etc
fixfiles -F relabel /
fixfiles -R setup check

8、audit2why
说明:检视SELinux audit讯息内容,提供检视/var/log/audit/audit.log内的记录资讯说明
使用范例:audit2why <  /var/log/audit/audit.log
注意:需要搭配启动auditd服务程式一起使用

9、sealert
说明:SELinux 讯息诊断用户端程序
参数如下:
-H, --html_output:使用网页格式输出(搭配 -a or -l 使用)
-l, --lookupid ID:检视指定ID的警示讯息
使用范例:
sealert -l xxxxx-xxxxx-xxxx
sealert -H -l xxxxx-xxxxx-xxxx > output.html
注意:需要搭配setroubleshoot服务一起使用
setroubleshoot服务启动后,会依据audit服务提供的资讯给予适当问题诊断,然后输出于/var/log/messages,该档案内会有相关输出资讯提供除错检视

10、semanage
说明:selinux policy维护工具
使用方式:semanage { login | user | port | interface | fcontext | translation} -l [-n]
使用范例:
semanage login -l
semanage user -l
semanage port -l
semanage port -a -t http_port_t -P tcp 81
semanage fcontext  -a  -t    httpd_sys_Context_t   "/home/users/(.+)/public_html(/.*)?“

11、secon
说明:检视程式、档案与使用者等相关SELinux Context
使用方式:
secon [-hVurtscmPRfLp] [CONTEXT]
secon [--file] FILE | [--link] FILE | [--pid] PID
参数:
-u, --user:show the user of the security context
-r, --role:show the role of the security context
-t, --type:show the type of the security context
-f, --file FILE:gets the context from the specified file FILE
-p, --pid PID:gets the context from the specified process PID
使用范例:
secon -u
secon -r
secon -t
secon --file /etc/passwd
secon --pid <pid>

转:http://www.cnblogs.com/zgx/archive/2011/08/31/2160330.html

SELinux 基础命令相关推荐

  1. Centos7 MYSQL安装与基础命令运用

    Centos7 MYSQL安装与基础命令运用 1.关闭防火墙,selinux systemctl stop firewalld setenforce 0 2.实现虚拟机能够上网,所以说要两块网卡,一块 ...

  2. Linux基础(2)-基础命令和bash的基础特性(1)

    基础命令 命令历史 命令历史的管理 登陆 shell 时,会读取命令历史文件中记录下的命令: ~/.bash_history . 登陆进 shell 后,新执行的命令只会记录在缓存中,这些命令会在用户 ...

  3. Linux基础命令(三).md

    目录 1.压缩工具之gzip 2.压缩工具之bzip2 3.压缩工具之xz 4.压缩工具之zip 5.归档工具tar 6.文本排序命令sort 7.文本去重命令uniq 8.基础命令之cut 9.高级 ...

  4. Linux 远程工具 基础命令

    Linux 远程工具 基础命令 文章目录 Linux 远程工具 基础命令 1.虚拟机关键配置名词解释 1.1.虚拟网络编辑器说明 2.远程链接工具 3.linux 命令准则 4.系统运行命令 5.常用 ...

  5. Linux基础命令-进程与系统性能

    Linux基础命令-进程与系统性能 进程与系统性能 一.进程相关概念 1.进程概念 2.进程的基本状态和转换 3.IPC进程间通信 4.进程优先级 5.进程状态 二.进程与系统性能 1.系统管理工具 ...

  6. Docker概述、安装及基础命令

    Docker概述.安装及基础命令 一.Docker概述 1. docker是什么 2. docker与虚拟机的区别 3. docker使用场景 4. docker核心概念 5. docker引擎 6. ...

  7. Red Hat Linux 基础命令大全

    Red Hat Linux 基础命令大全 1.startx                    从文本界面进入图形界面 2.ls  -lhar                  显示目录与文件 ls ...

  8. Rhel基础命令回顾和强制修改Rhel的root密码

    第一章  基础命令总结 ip a 和 ifconfig      查看当前属性下ip hostname             查看当前完整主机名 hostname   AAA   临时修改主机名为A ...

  9. linux 操作系统笔记基础命令

    文章目录 linux 基础命令 cd 命令详解 ls 命令详解 pwd 命令详解 hostname命令详解 clear命令详解 who.whoami.w 命令 which 命令 cal 命令详解 ld ...

最新文章

  1. Java 常用类库 之 Random 随机数类实例
  2. 如何安装最新版本的 SAP ABAP Development Tool ( ADT ) 2021年度更新
  3. 如何在vsc上下载php扩展包,正确的 Composer 扩展包安装方法
  4. OSPF的虚链路配置
  5. Vue 过渡效果的组件
  6. java jsr305_java – 为什么我需要添加神器JSR305才能使用Guava 14?
  7. 测试自己幸运数字的软件,心理测试:选一个你的幸运数字,测一下你最近会有什么好事发生?...
  8. Sphinx 文档例子
  9. 年货怎么到家早?华为云+AI 告诉你!
  10. 电脑销售渠道_小镇购买电脑遇难题:渠道少,价格无从比较!
  11. 强化学习(二)--动态规划寻找最优策略
  12. np合并 python_Python办公自动化自动更新不对称表格
  13. 从0开始写一个基于Flutter的开源中国客户端(7)——App网络请求和数据存储
  14. 凸优化第九章无约束优化 9.3梯度下降方法
  15. VS系列之【 产品密钥 – 所有版本】
  16. matlab节约里程法_节约里程法matlab.doc
  17. c语言在线翻译器,command(c语言翻译工具)
  18. IT计算机行业都有哪些证可以考
  19. Gmail终于对中文用户开放注册! update:2008.5.6
  20. Java不停机上线_不停机发布策略

热门文章

  1. Java 实例 - 查找 List 中的最大最小值
  2. 20190509杂题选讲
  3. C++回声服务器_6-多进程pipe版本服务器
  4. css中em单位和rem单位
  5. 拆轮子:requests
  6. Centos-redis安装配置
  7. PHP移动互联网开发(1)——环境搭建及配置
  8. bin和sbin区别
  9. 全新 HTML 5.1 工作草案发布
  10. HAProxy+Hive构建高可用数据挖掘集群