Detailed explanation of selinux basic configuration tutorial in Linux

Detailed explanation of selinux basic configuration tutorial in Linux

selinux ( Security-Enhanced Linux) is a Linux kernel module and a security subsystem of Linux.

Three modes :

Enforcing: Enforcement mode. When selinux is running, domain/type restrictions have begun.

permissive: Warning mode. When selinux is running, there will be a warning message, but the access of domain/type will not be restricted.

disabled: Disable mode.

You can use getenforce to check selinux status

The role of selinux on files:

When selinux is enabled, selinux will load a tag context for each file. The security context must be matched, otherwise the file cannot be accessed.

test:

###Enable selinux


insert image description here

Create files and move them to the ftp release directory

touch /mnt/filemv /mnt/file /var/ftp/

insert image description here

User logs in to ftp to view files


insert image description here

It can be found that anonymous users cannot read the files moved to ftp earlier

But the file exists in the ftp directory


insert image description here

View the security context of a file

ls -Z /var/ftp/

insert image description here

You can see that the security contexts of the two files are different, so they are not displayed.
Temporarily modify the security context

chcon -t public_content_t /var/ftp/file

insert image description here

Log in to ftp to view files


insert image description here

Since the security contexts are consistent, the file can be displayed.

chcon is only a temporary modification of the security context. When the system selinux is restarted, the modification will become invalid.

###Permanently modify the security context

##Create your own ftp home directory and modify the directory security context label

mkdir /ftphomesemanage fcontext -a -t pubilc_content_t '/ftphome(/.*)?'

###View the security context of the directory


insert image description here

Here you can see that the security context label has not been modified. We need to restart the kernel list service.

restorecon -RvvF /ftphome###R: recursive vv: display subdirectory or file modification information under the directory, F: force the file and directory security context in the directory to be consistent 

insert image description here

The security context has been modified


insert image description here

The role of selinux in services:

The effect of selinux on services is equivalent to adding a switch to the service, which is turned off by default. 1: turn on the switch; 0: turn off the switch

When selinux is turned on, we test the switching effect of selinux on the service by logging in to ftp.

insert image description here

Users cannot upload, delete, etc. files

Check the status of selinux switch for ftp


insert image description here

They are all in a closed state, so there are restrictions on user permissions

Turn on the function switch

setsebool -P ftp_home_dir on setsebool -P ftpd_anon_write on 

insert image description here

Log in to ftp again, users can upload files


insert image description here

Install setroubleshoot, which can provide solutions to selinux error logs

/var/log/audit/audit.log ###Record the log collected by selinux 

insert image description here

Download /var/log/audit/audit.log ###Record the log collected by selinux 

insert image description here

Summarize

The above is a detailed explanation of the basic configuration tutorial of selinux in Linux introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Detailed explanation of SELINUX working principle
  • SELinux Getting Started
  • Briefly describe SELinux TE in Android
  • Detailed explanation of Android Selinux permissions and issues
  • Detailed explanation of the problem of SELinux preventing MongoDB from starting under CentOS 7 system
  • SELinux causes PHP to connect to MySQL abnormally. Solution to Can't connect to MySQL server
  • How to disable selinux (firewall)
  • How to understand SELinux under Linux

<<:  Some methods to optimize query speed when MySQL processes massive data

>>:  Vue data two-way binding implementation method

Recommend

Solution to find all child rows for a given parent row in MySQL

Preface Note: The test database version is MySQL ...

JavaScript canvas to achieve mirror image effect

This article shares the specific code for JavaScr...

How to install mysql5.6 in docker under ubuntu

1. Install mysql5.6 docker run mysql:5.6 Wait unt...

A Brief Analysis on the Time Carrying Problem of MySQL

The default time type (datetime and timestamp) in...

CSS writing format, detailed explanation of the basic structure of a mobile page

1. CSS writing format 1. Inline styles You can wr...

HTML iframe usage summary collection

Detailed Analysis of Iframe Usage <iframe frame...

MySQL free installation version configuration tutorial

This article shares the MySQL free installation c...

Vant+postcss-pxtorem implements browser adaptation function

Rem layout adaptation The styles in Vant use px a...

Sample code for implementing history in vuex

I have recently been developing a visual operatio...

Summary of changes in the use of axios in vue3 study notes

Table of contents 1. Basic use of axio 2. How to ...

Solution to MySql service disappearance for unknown reasons

Solution to MySql service disappearance for unkno...

How to install elasticsearch and kibana in docker

Elasticsearch is very popular now, and many compa...