I accidentally removed all regular users from the sudoers configuration on a RHEL 8 server. I still have a non-root account, but attempts to reboot fail with messages about interactive authentication, logind, initctl permissions, and being unable to set the wall message. I considered adding a polkit rule to permit one user to reboot, but the policy files are owned by root. What is the safest way to regain administrative access or restart the system?
4 Answers
Booting into an authorized rescue environment is another standard recovery path. Mount the installed system, enter its chroot, repair the sudoers file or reset the root credentials according to your organization's procedure, and check filesystem labels and permissions before rebooting. Avoid creating a second account with UID 0 or using an unpatched local privilege-escalation exploit; those approaches create serious security and audit problems.
If this is a physical machine or a VM with console access, use the management console's Ctrl+Alt+Delete or graceful power-control option. Hardware management such as IPMI/BMC can also issue a soft power action. A graceful shutdown is preferable to pulling power, even after syncing filesystems.
A polkit rule can allow a user to reboot, but creating or changing that rule requires root access in the first place. You need to restore administrative access before changing policy. If you have a backup of sudoers, use an approved recovery method to restore it and validate the file before rebooting.
For a remote VM or cloud instance, ask the infrastructure administrator to perform a controlled restart or provide console access. Depending on the platform, the disk can be attached to a rescue system so the sudoers configuration can be repaired offline. Make sure the filesystem is mounted appropriately and validate sudoers before bringing the server back.

Related Questions
Can't Load PhpMyadmin On After Server Update
Redirect www to non-www in Apache Conf
How To Check If Your SSL Cert Is SHA 1
Windows TrackPad Gestures