One of the worst feelings you can experience after putting so much time and effort into your dedicated server is to suddenly realize you are unable to control it. Aside from security breaches, the most common reason for this is that you forgot your password. Forgetting a user password is unfortunate, but not the end of the world. If you forget your root password, however, you will be cut off from administrative access to your server.
Although the situation may seem impossible to remedy, Linux servers do offer a way to regain control, but it will require direct access to the system console. If your server is at a remote location, find out if your hosting provider or data center administrator can provide access via a KVM interface.
Once you are able to witness and interact with the system prior to booting, you can interrupt the boot process and login as root directly. In CentOS, for example, you need to interupt Grub before the OS boots by pressing any key. You then need to modify the “kernel” line by scrolling down to it and pressing “e”. Press “e” again to begin editing the line.
Next, press Backspace to remove “rhgb quiet”. In its place, type “selinux=0 1” and press Enter. Finally, press “b” to boot your new kernel line. The system will appear to boot normally, but instead of taking you to a login screen, it will take you directly to the command prompt, and you will be logged in as root in runlevel 1.
Once you reach the login prompt, disable SELinux with “setenforce=0”. You can then change the password with the “passwd” command.