Перейти к содержимому

Как проверить статус selinux

  • автор:

HowTo: Disable SELinux

SELinux is an access control tool that is installed and activated by default in such Linux distributions like RHEL (Red Hat Enterprise Linux), CentOS and Fedora.

If you’ve setup a new system, or installed some new application and it is not working, then you have to check SELinux, because it may be the cause of the problem.

In this article you’ll learn how to check the current status of SELinux, how to disable or enable SELinux temporarily or permanently.

Check the Status of SELinux

Run the following command to check if SELinux is running:

getenforce reports whether SELinux is Enforcing, Permissive, or Disabled.

Disable SELinux Temporarily

The following modifications are temporary and they will be gone after reboot.

Turn OFF SELinux Temporarily

Use the following command to disable SElinux temporarily.

Turn ON SELinux Temporarily

Use the following command to enable SElinux temporarily.

Disable SELinux Permanently

From the command line, edit the /etc/selinux/config file.

Turn OFF SELinux Permanently

Change the SELINUX= line in /etc/selinux/config file to:

Turn ON SELinux Permanently

Change the SELINUX= line in /etc/selinux/config file to:

How To Check SELinux Status?

SELinux or Security Enhanced Linux provides extra security for Linux distributions. SELinux is generally installed on enterprise Linux distributions like Ubuntu Server, RHEL, CentOS, etc., and generally enabled by default. But this case may change according to different situations. SELinux provides 3 modes called Enforcing , Permissive and Disabled . In this tutorial, we explain how to check the SELinux status.

Check SELinux Status with sestatus Command

The easiest and most popular way is using the sestatus command in order to print the SELinux status. There is no need for an extra privilege where a regular user can execute the sestatus command.

Check SELinux Status with getenforce Command

Another useful command to check SELinux status is getenforce command. It is very similar to the sestatus command. But the getenforce command outputs a very simple description that only shows the current mode.

Check SELinux Status via /etc/selinux/config File

The /etc/selinux/config file is used to store SELinux configuration. This configuration file also stores the status of the SELinux. By printing this file the SELinux status can be displayed. The SELINUX line shows the SELinux status.

Check SELinux Status via /etc/selinux/config File

How to effectively deal with bots on your site? The best protection against click fraud.

В нашей предыдущей статье о SELinux мы рассказали вам о способе его отключения. SELinux позволяет вам ограничивать права, связанные с выполнением процесса, и уменьшать ущерб, который может возникнуть в результате эксплуатации уязвимостей в приложениях и системах. По этой причине, если у вас нет веской цели для его отключения, рекомендуется оставить SELinux в принудительном режиме. Однако сегодня мы хотели бы поделиться с вами методом проверки статуса SELinux в CentOS 8.

Пример использования проверки статуса SELinux в CentOS 8

После прочтения введения к этой статье у вас может возникнуть вопрос, зачем нам вообще нужно проверять статус SELinux. Мы уже заявляли, что безопасность систем на базе Linux полностью зависит от SELinux. Это означает, что вы должны постоянно следить за тем, чтобы SELinux был включен и работал в вашей системе, если только вы не столкнетесь с ситуацией, когда вам придется отключить его явно.

Поскольку это механизм, который работает в фоновом режиме, пользователи не знают о его статусе. Им нужно специально запросить его статус, чтобы узнать, включен или отключен SELinux. Если он включен, то в каком режиме он работает? Это «принудительное» или «разрешительное»? В этой ситуации у нас должны быть надлежащие способы узнать статус SELinux.

Чтобы узнать о различных методах проверки статуса SELinux в CentOS 8, вам необходимо изучить следующий раздел этой статьи.

Методы проверки статуса SELinux в CentOS 8

Для проверки статуса SELinux в CentOS 8 вы можете использовать любой из трех методов, описанных ниже.

Метод 1. Использование команды «sestatus»

Это самый простой и легкий способ узнать статус SELinux, поскольку он включает только однострочную команду. Чтобы использовать команду «sestatus» для проверки статуса SELinux в CentOS 8, вам необходимо запустить эту команду в своем терминале следующим образом:

Выполнение этой команды отобразит много информации, кроме статуса SELinux в CentOS 8. В нашем случае был включен SELinux; следовательно, его статус установлен на «включен», как показано на изображении ниже:

Вам необходимо изменить файл конфигурации, чтобы отключить SELinux в CentOS 8. Для этого вы должны сначала получить доступ к файлу конфигурации с помощью любого текстового редактора по вашему выбору. Вы можете перемещаться по файлу конфигурации SELinux в CentOS 8, выполнив прикрепленную команду на терминале:

$ sudo nano / и т.д. / selinux / config

После успешного выполнения вышеупомянутой команды файл конфигурации SELinux будет открыт в редакторе nano, то есть редакторе по умолчанию. Вам необходимо перейти к переменной с именем «SELinux» и изменить ее текст с «включен» на «отключен». После этого вам необходимо сохранить и закрыть этот файл конфигурации. Однако рекомендуется оставить статус SELinux включенным.

Метод 2. Использование команды getenforce

Это еще один простой способ узнать статус SELinux, поскольку он также включает однострочную команду. Если вы просто хотите узнать, в каком режиме SELinux работает при включении в CentOS 8, вы можете использовать команду «getenforce» следующим образом:

Выполнение этой команды не отобразит никакой другой информации, а просто покажет, что ваш SELinux в настоящее время работает в «принудительном» режиме, как показано на изображении, показанном ниже:

Метод 3: Использование файла «/ etc / selinux / config»

Если вы не удовлетворены тем, что видите только статус SELinux на терминале, выполнив простую команду, вы также можете взглянуть на файл / etc / selinux / config в CentOS 8. Вся информация, касающаяся настроек и статуса SELinux, хранится в файле / etc / selinux / config. Поэтому, если вы хотите увидеть статус SELinux в CentOS 8, вы также можете выбрать отображение содержимого этого файла, выполнив команду «cat» ниже:

$ cat / etc / selinux / config

Как только вы запустите эту команду, файл конфигурации SELinux, / etc / selinux / config, будет отображаться на вашем компьютере. терминал, из которого вы можете легко определить статус SELinux в CentOS 8, как показано на изображении. ниже:

Вывод

SELinux — это утилита Linux, которая предлагает обходной путь в ядре Linux, чтобы помочь политикам безопасности контроля доступа. Используя любой из трех методов, обсуждаемых в этой статье, вы можете легко узнать статус SELinux в CentOS 8. Все три описанных здесь метода одинаково эффективны, и пользователь может выбрать тот метод, который ему больше всего нравится. Зная статус SELinux, вы также можете включить его, если он был случайно или намеренно отключен в прошлом. Следуя этому руководству, вы теперь можете проверить статус SELinux на вашем CentOS 8.

Я надеюсь, что эта статья поможет вам при проверке статуса SELinux в вашей операционной системе Linux. Если у вас возникнут трудности, вы можете задать вопрос в разделе комментариев.

How to Check SELinux Status?

In our previous article on SELinux, we shared with you the method of disabling it. SELinux allows you the power to restrict the rights related to the process execution and mitigate the damage that might emerge from the exploitation of vulnerabilities in applications and systems. For this reason, unless you have a valid purpose to disable it, it is suggested to keep SELinux in enforcing mode. However, today we would like to share with you the method of checking the status of SELinux on CentOS 8.

Use Case of Checking the Status of SELinux on CentOS 8

After reading the introduction of this article, you might be wondering why do we need to check the status of SELinux in the first place. We have already stated that the security of the Linux based systems relies entirely on SELinux. It means that you should ensure all the time that SELinux is enabled and running on your system, unless you encounter a situation in which you have to disable it explicitly.

Since it is a mechanism that runs in the background, therefore, the users are not aware of its status. They need to specifically query for its status to know if SELinux is enabled or disabled. If it is enabled, then in which mode is it operating? Is it “Enforcing” or “Permissive”? In this situation, we must have proper ways where we can inquire for the status of SELinux.

For knowing the different methods of checking SELinux status on CentOS 8, you need to go through the following section of this article.

Methods of Checking SELinux Status on CentOS 8

For checking the status of SELinux on CentOS 8, you can use any of the three methods described below.

Method 1: Using the “sestatus” Command

This is the simplest and easiest method of finding out the status of SELinux as it only includes a one-liner command. For using the “sestatus” command for checking the status of SELinux on CentOS 8, you need to run this command in the following manner in your terminal:

Running this command will display a lot of information other than the status of SELinux on CentOS 8. In our case, SELinux was enabled; therefore, its status is set to “enabled” as highlighted in the image shown below:

You have to modify the configuration file to disable SELinux on CentOS 8. To do that, you must first access the configuration file using any text editor of your preference. You can navigate the SELinux configuration file on CentOS 8 by running the affixed command on the terminal:

After the successful execution of the above-mentioned command, the SELinux configuration file will be open in nano editor, i.e., default editor. You have to navigate the variable named as ‘SELinux’ and change its text from ‘enabled’ to ‘disabled’. After that, you have to save and close this configuration file. However, it is suggested to keep the SELinux status as enabled.

Method 2: Using the “getenforce” Command

This is another simple method of finding out the status of SELinux since this also involves a one-liner command. If you just want to know the mode of SELinux on which it is operating while being enabled on CentOS 8, you can make use of the “getenforce” command in the following manner:

Running this command will not display any other information, rather it will simply reveal that your SELinux is currently operating in the “enforcing” mode as highlighted in the image shown below:

Method 3: Using the “/etc/selinux/config” File

If you are not satisfied by seeing only the status of SELinux on the terminal by running a simple command, then you can also choose to take a look at the /etc/selinux/config file in CentOS 8. All the information regarding the settings and status of SELinux is stored in the /etc/selinux/config file. Therefore, if you wish to see the status of SELinux on CentOS 8, you can also choose to display the contents of this file by running the “cat” command below:

As soon as you run this command, the configuration file of SELinux, /etc/selinux/config, will be displayed on your terminal, from which you can easily figure out the status of SELinux on CentOS 8 as highlighted in the image shown below:

Conclusion

SELinux is a Linux utility that offers a workaround in the Linux kernel to help access control security policies. By using any of the three methods discussed in this article, you can easily find out the status of SELinux on CentOS 8. All three methods shared here are equally effective, and the user can choose to follow whichever method they like the most. By knowing the status of SELinux, you can also enable it if it has been accidentally or deliberately disabled in the past. By following this tutorial, you are now able to check the status of SELinux on your CentOS 8.

I hope this article will help you while checking SELinux status on your Linux operating system. In case you come up with any difficulty, you can ask in the comment section.

About the author

Aqsa Yasin

I am a self-motivated information technology professional with a passion for writing. I am a technical writer and love to write for all Linux flavors and Windows.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *