新手上路:学会使用SELinux保护你的系统

1 Selinux的介绍

SELinux是为了提高系统安全性的机制。

它对系统的每一个程序、文件都引入了安全上下文。安全上下文标签,用于唯一标识文件、进程和资源。这些标签包括了安全策略的信息,允许SELinux强制执行策略。

1.1 Selinux关闭状态下

bash 复制代码
getenforce # 查看selinux开启状态
/etc/selinux/config # 在此文件中可以修改selinux的开启与关闭



1.2 Selinux开启状态下

2 Selinux的开启与关闭

2.1 Selinux的永久开启与关闭

selinux的开启与关闭切换需要reboot系统

bash 复制代码
/etc/selinux/config # 修改文件
SELINUX=disabled #selinux关闭
SELINUX=enforcing #selinux开机设定为强制状态此状态为selinux开启
SELINUX=permissive #selinux开机设定为警告状态此状态为selinux开启

2.2 Selinux的临时修改

bash 复制代码
selinux开启后强制和警告级别的转换
setenforce 0 ##警告
setenforce 1 ##强制


3 Selinux的安全上下文

3.1 查看安全上下文

bash 复制代码
ls -Z ##查看文件的安全上下文
ls -Zd ##查看目录的安全上下文
ps axZ ##查看进程的安全上下文

3.1 临时修改安全上下文

bash 复制代码
chcon -t public_content_t /var/ftp/westosfile1 # public_content_t是安全上下文标签
chcon -Rt public_content_t /westosdir #修改目录及目录中的所有子文件的安全上下文

3.2 永久修改安全上下文

bash 复制代码
semanage fcontext -l | less ##查看内核安全上下文列表
semanage fcontext -a -t public_content_t '/westosdir(/.*)?' # 修改安全上下文
semanage fcontext -d -t public_content_t '/westosdir(/.*)?' # 恢复安全上下文为默认
restorecon -RvvF /westosdir/  # 刷新
touch /.autorelabel ##重启系统时selinux初始化文件标签开关文件



4 SEBOOL

bash 复制代码
getsebool -a ##现实服务的bool值
setsebool -P ftpd_anon_write on #更改

5 SEPORT 端口设定

bash 复制代码
semanage port -l | grep ssh # 查看允许的端口号
semanage port -a -t ssh_port_t -p tcp 1111 # 将想要使用的端口号添加到seport表中


6 Selinux排错

bash 复制代码
rpm -qa | grep setrouble # 基于此服务为selinux提供排错功能
/var/log/audit/audit.log ##selinux警告信息
/var/log/messages ##selinux问题解决方案
相关推荐
安迪小宝5 分钟前
6 任务路由与负载均衡
运维·python·celery
遇见火星15 分钟前
jenkins流水线常规配置教程!
运维·docker·jenkins
愚戏师32 分钟前
Linux复习笔记(六)shell编程
linux·笔记·shell
大胆飞猪1 小时前
Linux操作系统--进程间通信(system V共享内存)
linux
LunarCod1 小时前
Ubuntu使用Docker搭建SonarQube企业版(含破解方法)
linux·运维·服务器·ubuntu·docker·开源·sonarqube
betazhou1 小时前
基于Linux环境实现Oracle goldengate远程抽取MySQL同步数据到MySQL
linux·数据库·mysql·oracle·ogg
什么半岛铁盒2 小时前
Linux信号的保存
linux·运维·网络
百锦再2 小时前
大数据技术的主要方向及其应用详解
大数据·linux·网络·python·django·pygame
2301_803554522 小时前
vim,gcc/g++,makefile,cmake
linux·编辑器·vim
noravinsc2 小时前
国产化中间件 替换 nginx
运维·nginx·中间件