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

Install centos7 virtual machine on win10

1. Download VMware Workstation 64 version https:/...

How to completely uninstall Docker Toolbox

Docker Toolbox is a solution for installing Docke...

Practical method of deleting files from Linux command line

rm Command The rm command is a command that most ...

CentOS installation mysql5.7 detailed tutorial

This article shares the detailed steps of install...

The difference between html empty link href="#" and href="javascript:void(0)"

# contains a location information. The default anc...

A brief discussion on MySQL index optimization analysis

Why are the SQL queries you write slow? Why do th...

Detailed description of component-based front-end development process

Background <br />Students who work on the fr...

CSS performance optimization - detailed explanation of will-change usage

will-change tells the browser what changes will h...

The iframe refresh method is more convenient

How to refresh iframe 1. To refresh, you can use j...

CentOS7.5 installation tutorial of MySQL

1. First check whether the system has mysql insta...

Detailed explanation of CSS float property

1. What is floating? Floating, as the name sugges...