Hexa's Blog

SELinux, cannot login to shell after enable it

30/11/2024 @ Saigon Linux

After along time disable SELinux, now you might want to enable it in Enforcing mode. After OS boot, in terminal, you may not login even though you did enter correct username/password. It’s because your files not to be labeled or labeled with SELinux context not matching the install policy.

The solution is that you ask SELinux to re-label in the next reboot. Enter the following command.

$ touch /.autorelabel

Then reboot!

In case you forget to do it. you need to go to rescue mode while booting the system, the GRUB2 menu will be displayed. To boot the system into rescue mode using bash follow these steps:

  • Select the boot entry you wish to edit with the arrow keys.
  • Select the entry you wish to edit by pressing e.
  • Use the arrow keys to go to select the line beginning with linux, linux16, or linuxefi.
  • Go the the end of that line and include a space and the following rw init=/bin/bash. If your disk is encrypted, you may need to add plymouth.enable=0
  • Press Ctrl-x or F10 to boot the entry
  • Then enter command line touch /.autorelabel and reboot!

Good luck!

Refereces: