Home Operation and Maintenance Linux Operation and Maintenance Familiar with the three working modes of SELinux

Familiar with the three working modes of SELinux

Feb 26, 2024 pm 03:27 PM
selinux understand Operating mode

Familiar with the three working modes of SELinux

SELinux (Security-Enhanced Linux) is a security module that implements Mandatory Access Control (MAC) in Linux systems. It enforces security policies by applying labels to system objects (files, processes, etc.) for more fine-grained access control. SELinux has three working modes: Enforcing, Permissive and Disabled. This article will introduce these three modes in detail and provide specific code examples.

1. Enforcing mode

Enforcing mode is the safest and recommended mode, which enforces SELinux policies and denies and logs violations. In Enforcing mode, the system denies unauthorized access and generates corresponding log records. To understand Enforcing mode, we can go through the following code example to demonstrate how to set the SELinux label of a file and try to access it:

# 创建测试文件
touch testfile

# 查看文件的SELinux标签
ls -Z testfile

# 修改文件的SELinux标签为httpd_sys_content_t类型
chcon -t httpd_sys_content_t testfile

# 尝试访问文件
cat testfile
Copy after login

In the above example, we created a file named testfile and SELinux it The label is set to type httpd_sys_content_t. Attempting to read this file will result in access being denied because the file's label does not match the current process's label.

2. Permissive mode

Permissive mode allows system administrators to test SELinux policies without actually intercepting any access requests. In Permissive mode, SELinux will log access violations but will not deny them. This mode is typically used for debugging and testing new SELinux policies. The following is an example that demonstrates how to view log records in Permissive mode:

# 查看当前SELinux模式
sestatus

# 切换SELinux模式为Permissive
setenforce 0

# 尝试访问被禁止的文件
cat /etc/shadow

# 查看SELinux日志记录
cat /var/log/audit/audit.log
Copy after login

In the above example, we switch the SELinux mode to Permissive and try to read the /etc/shadow file, at which point the log records will Displays information about blocked access, but actual access is still allowed.

3. Disabled mode

Disabled mode will completely disable SELinux and cancel any access control and protection measures related to SELinux. This is the least recommended mode as the security of the system will be affected. In Disabled mode, the system will not execute SELinux policies and will not record any illegal access. The following is an example demonstrating how to disable SELinux:

# 查看当前SELinux模式
sestatus

# 禁用SELinux
setenforce 0

# 查看当前SELinux模式
sestatus
Copy after login

In the above example, we disabled SELinux through the setenforce command and verified that SELinux is in Disabled mode through the sestatus command.

Summary: Understanding the three working modes of SELinux is crucial for system security and access control. Enforcing mode provides the highest level of protection, Permissive mode is used for debugging and testing, and Disabled mode should be avoided to ensure system security. Through the above specific code examples, I hope readers can have a deeper understanding of the working mode of SELinux and its advantages and disadvantages.

The above is the detailed content of Familiar with the three working modes of SELinux. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is SELinux What is SELinux Feb 08, 2023 am 11:56 AM

SELinux refers to security-enhanced Linux. It is a security subsystem of Linux. It is designed to enhance the security of the traditional Linux operating system and solve various permission problems in the discretionary access control (DAC) system of the traditional Linux system (such as excessive root permissions). higher). SELinux uses a mandatory access control (MAC) system, which controls whether a process has access rights to files or directories on a specific file system.

In-depth understanding of how to use Linux pipelines In-depth understanding of how to use Linux pipelines Feb 21, 2024 am 09:57 AM

In-depth understanding of the use of Linux pipes In the Linux operating system, pipes are a very useful function that can use the output of one command as the input of another command, thereby conveniently realizing various complex data processing and operations. A deep understanding of how Linux pipes are used is very important for system administrators and developers. This article will introduce the basic concepts of pipelines and show how to use Linux pipelines for data processing and operations through specific code examples. 1. Basic concepts of pipes in Linux

Understand the importance of Go language comments Understand the importance of Go language comments Mar 29, 2024 pm 04:48 PM

Comments are a very important part of Go programming. Comments can help programmers better understand the logic, purpose, and details of the code, thereby improving the readability and maintainability of the code. This article will introduce the importance of comments in the Go language, and combine it with specific code examples to illustrate how comments help code understanding. First, let's look at a simple Go program example: packagemainimport "fmt" funcmain(){/

How to correctly understand value passing in PHP How to correctly understand value passing in PHP Mar 08, 2024 pm 03:30 PM

How to correctly understand the value passing method in PHP PHP is a scripting language widely used in Web development, and the parameter passing methods in PHP mainly include value passing and reference passing. And understanding how values ​​are passed in PHP is crucial to writing efficient code. This article will discuss the value passing method in PHP in detail and use specific code examples to help readers better understand. The basic concept of value passing method is to copy the value of a variable and pass it to a function or method. Operations on the value within the function will not affect it.

In-depth understanding of the strings.Split function in Go language documentation In-depth understanding of the strings.Split function in Go language documentation Nov 04, 2023 pm 01:14 PM

To deeply understand the strings.Split function in the Go language documentation, specific code examples are required. In the Go language, string operations are a very common requirement. Among them, the strings package is a standard package provided by the Go language and provides a wealth of string processing functions. Among them, the strings.Split function is one of the commonly used functions. Its function is to split a string into a string slice according to the specified delimiter. Before we officially dive into the strings.Split function,

Understanding the middleware of ThinkPHP6 Understanding the middleware of ThinkPHP6 Jun 20, 2023 am 10:03 AM

As the complexity of modern web applications continues to increase, code logic is becoming more and more complex. To solve this problem, middleware is becoming more and more popular in modern web development. ThinkPHP6 is a popular PHP framework that also supports middleware. In this article, we will discuss the basics and practical uses of ThinkPHP6 middleware. What is middleware? In web development, middleware refers to a way of processing HTTP requests and responses. When the client sends a request to the server,

An in-depth analysis of the three policy types of SELinux An in-depth analysis of the three policy types of SELinux Feb 26, 2024 pm 10:24 PM

Detailed explanation of the three policy types of SELinux and code examples SELinux (Security-EnhancedLinux) is a security subsystem that implements mandatory access control on the Linux operating system. It ensures the security of the system by defining mandatory access rules for each operation. In SELinux, there are three main policy types: Enforcing, Permissive, and Disabled. This article will introduce these three in detail

Explain in simple terms: Thoroughly understand the working principle of Go language range Explain in simple terms: Thoroughly understand the working principle of Go language range Mar 12, 2024 pm 02:18 PM

Go language is a concise and powerful programming language with unique design and features in many aspects. One of the most impressive features is the range keyword, which is used to iterate over data structures such as arrays, slices, maps, and channels. The flexibility and convenience of range make it easy to traverse complex data structures, but many people are confused about how it works. This article will explain how range works in a simple and in-depth way, and use specific code examples to help readers better understand. First, let's look at a simple example

See all articles