
List of content you will read in this article:
- 1. Prerequisites
- 2. How to change the root password
- 3. How to reset root password in CentOS
- 4. Final words
The reason for this is security, which keeps the users from damaging the system permanently or accidentally exposing it to threats. That being said, if you are (or have) a root user and forgot the password, it will be impossible to have complete access to the system.
This guide will explain how you can reset the root password in CentOS systems. The following method is suitable for the following versions:
- CentOS 6
- CentOS 7
- CentOS 8
Prerequisites
- A server/machine running a CentOS operating system
- Basic knowledge of Linux commands
How to change the root password
First, let’s go through the process of changing the root password. To change the root password, enter the following command:
sudo passwd root
When you enter this command, the system will prompt you to enter your existing password. Enter the current password and enter the new password, respectively.
Note that this command will work for the root user or any user with root privileges.
How to reset root password in CentOS
In order to reset your root password in CentOS, you will need to access the boot menu. To access the boot menu for 1Gbits VPS servers, you need to be connected to the server through a console. To access the console:
- Login to the 1Gbits dashboard
- Head over the control panel
- Click on the VNC icon
- Select “Launch HTML 5 VNC Client”
- You will see the VNC window similar to the one shown below.
In order to access the boot menu:
- Restart the system
- Tap the Esc key about once per second to launch the GRUB menu
- Use arrow keys to highlight the Linux version you booting from
- Press e to enter the GRUB edit mode.
- Scroll down till you find the line starting with Linux 16. Here change the ro with rw init=/sysroot/bin/sh
- Now press Ctrl + x to start the system on single-user mode (this is needed to reset the password).
- To access the system, enter the following command.
chroot /sysroot
- Reset the password by:
passwd root
- Update the SELinux information using this command:
touch /.autorelabel
- Exit the chroot and reboot your system.
exit
reboot
Once your system is restarted successfully, confirm that your new password works by logging in.
For CentOS 6
- As the system boots, GRUB prompts you to press any key to stop the boot process. Press a key quickly; you only have a few seconds. If you miss the prompt, you need to restart the server from the control panel and try again.
- At the GRUB prompt, type A to append to the boot command.
- Add a space and the text single to the end of the line.
- Press ENTER.
- The system will boot, and you will see the root prompt.
- Type passwd and follow the prompts to change the root password.
- Run reboot to reboot the server.
Final words
If you already have access to your user accounts, resetting or changing your password in the Linux VPS system is quite simple. It can be more challenging if you’ve lost or forgotten a password, but you can get your accounts back with a little creative restarting and editing some files.
Let us know if you encounter any errors when using the above commands.
People also read: