This tutorial will go through the steps to reset the root password in CentOS. In Linux, root privileges (root access) is similar to Administrative account in Windows. A root user will have complete access to all the files, applications, configurations, and system functionality. Most user accounts on Linux run with limited privileges, which is recommended if you’re using the system.
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.
Let us know if you encounter any errors when using the above commands.
For a deeper understanding of CentOS and its functionalities, you can check out our article on What is CentOS. This resource will provide you with essential information about the operating system and help you navigate its features more effectively.
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. If you're using CentOS for server management, this process remains straightforward and efficient.
Additionally, if you're planning to install or configure software after resetting your password, you may need to install the Ioncube loader. For a detailed guide on this process, check out our tutorial on installing Ioncube Loader on CentOS.
Let us know if you encounter any errors when using the above commands.
People also read:
- How to reset Ubuntu Root Password
- How to switch to a root account in Ubuntu?
- How to upgrade centos 7 to 8?
- How to install xcache php centos?
- Install lemp on centos 7
- Install mysql centos 7