Disclaimer: This question is not to solve the problem of changing root password while SELinux is active because there are a lot of guides to solve that already. This is more of how SELinux does that internally.
I'm a recent user of SELinux but lately I've been more in touch with it. There was a moment when someone asked me how I could reset root password in case of forgetting it.
So I booted my CentOS, edited grub entry to something like
linux16 <kernel_location> root=/dev/mapper/centos-root rw init=/bin/bash
I ran passwd
and afterwards ran sync
and forced reboot.
After reboot, logging in with the new password was rejected as well as with the old of course.
Rebooted again and passed the kernel the parameter to disable SELinux (selinux=0
). Tried logging in with the new password and it worked.
Afterwards I forced a fs auto relabel (via the file .autorelabel
) and with SELinux active it was now possible to log in.
My question is: why does happen? Why does relabeling affect log in when there was merely a change of password and not of users or objects?
Thank you for your attention.
TL;DR: Usual root password reset doesn't work in SELinux. Why?
Edit: This was tested on a virtual machine running CentOS7 with KVM as hypervisor.