SElinux

SELinux 是Security-Enhanced Linux的缩写,意思是安全强化的linux

SELinux 主要由美国国家安全局(NSA)开发,当初开发的目的是为了避免资源的误用传统的访问控制在我们开启权限后,系统进程可以直接访问

当我们对权限设置不严谨时,这种访问方式就是系统的安全漏洞

在开启SElinux后

会对进程本身部署安全上下文

会对文件部署安全上下文

会对服务使用端口进行限制

会对程序本身的不安全功能做限制

[root@localhost ~]# grubby --update-kernel ALL --args selinux=1

[root@localhost ~]# reboot

[root@localhost ~]# dnf install vsftpd -y

[root@localhost ~]# vim /etc/vsftpd/vsftpd.conf

[root@localhost ~]# systemctl enable --now vsftpd

[root@localhost ~]# dnf install lftp -y

[root@localhost ~]# touch /mnt/file

[root@localhost ~]# mv /mnt/file /var/ftp/

[root@localhost ~]# cd /var/ftp/

[root@localhost ftp]# ls

file pub

[root@localhost ftp]# ls -Z

unconfined_u:object_r:mnt_t:s0 file system_u:object_r:public_content_t:s0 pub

[root@localhost ftp]# chcon -t public_content_t file

Selinux 重启的标识文件 文件存在 在重启系统后会重新初始化

[root@localhost ftp]# touch /mnt/leefile

[root@localhost ftp]# ls -Z /mnt/leefile

unconfined_u:object_r:mnt_t:s0 /mnt/leefile

[root@localhost mnt]# semanage fcontext -a -t public_content_t '/mnt/leefile(/.*)?'

[root@localhost mnt]# semanage fcontext -l | grep leefile

永久设置安全上下文

[root@localhost mnt]# ls -Z /mnt/leefile

unconfined_u:object_r:mnt_t:s0 /mnt/leefile

[root@localhost mnt]# restorecon -RvvF /mnt/leefile

Relabeled /mnt/leefile from unconfined_u:object_r:mnt_t:s0 to system_u:object_r:public_content_t:s0

selinux 对linux服务的影响

服务的功能影响

在系统SElinux开启后会为服务添加新的功能开关,我们把这个开关叫做sebool

[root@localhost mnt]# setsebool -P ftpd_anon_write on 修改sebool值

[root@localhost mnt]# getsebool -a | grep ftp 查看sebool

ftpd_anon_write --> on

ftpd_connect_all_unreserved --> off

ftpd_connect_db --> off

ftpd_full_access --> off

ftpd_use_cifs --> off

ftpd_use_fusefs --> off

ftpd_use_nfs --> off

ftpd_use_passive_mode --> off

httpd_can_connect_ftp --> off

httpd_enable_ftp_server --> off

tftp_anon_write --> off

tftp_home_dir --> off

服务的端口影响

在系统SElinux开启后会规定服务使用端口

查看服务被允许使用的端口

[root@localhost ~]# semanage port -l | grep ssh

ssh_port_t tcp 22

[root@localhost ~]# semanage port -a -t ssh_port_t -p tcp 8888

[root@localhost ~]# semanage port -l | grep ssh

ssh_port_t tcp 8888, 22

相关推荐
誰能久伴不乏1 分钟前
Linux系统调用概述与实现:深入浅出的解析
linux·运维·服务器
程序员学习随笔13 分钟前
Linux进程深度解析(2):fork/exec写时拷贝性能优化与exit资源回收机制(进程创建和销毁)
linux·运维·服务器
mmoyula13 分钟前
【RK3568 PWM 子系统(SG90)驱动开发详解】
android·linux·驱动开发
-SGlow-33 分钟前
MySQL相关概念和易错知识点(2)(表结构的操作、数据类型、约束)
linux·运维·服务器·数据库·mysql
代码改变世界ctw1 小时前
Linux内核设计与实现 - 第14章 块I/O层
linux·运维·服务器
Dreams_l1 小时前
网络编程2(应用层协议,传输层协议)
运维·服务器·网络
勇哥的编程江湖2 小时前
starrocks官网docker部署mysql无法连接
运维·docker·容器
EulerBlind3 小时前
【运维】SGLang 安装指南
运维·人工智能·语言模型
van叶~3 小时前
Linux网络-------1.socket编程基础---(TCP-socket)
linux·网络·tcp/ip
风吹落叶花飘荡4 小时前
Ubuntu系统 系统盘和数据盘扩容具体操作
linux·运维·ubuntu