Data is precious. Some people are even calling it the new Gold. It is essential to change your password from time to time to ensure that your data remains protected from malicious activities. Most people only have a single password for everything, and they use it for years which is an unsafe practice and can expose them to dangerous cybercrimes like identity theft. When setting a password, one should always ensure to set a unique and strong password.This article will present an extensive guide on changing your password on CentOS 8 operating system by using two different methods.
- Through GUI
- Through Terminal
- Method 1: Changing the User Password through GUI
- Method 2: Changing the User Password through Terminal
- How to change another user’s Password in CentOS
- Conclusion
- About the author
- Resetting Forgotten Root Password
- Resetting Root password from Terminal
- Conclusion
- About the author
- About the author
- Reset Forgotten root Password in CentOS 8
- Reset Forgotten Root Password in RHEL/CentOS & Fedora
- Open Terminal
- Log in as admin or root user
- Step 3. Change the sudo password using the passwd command
- Log off or terminate the root terminal session
- Shortcut alternative
- Summary
- Prerequisites
- Change root password using passwd
- Change root password using su
- Conclusion
Method 1: Changing the User Password through GUI
Step 1: First, open the dropdown menu from the top right corner:
Step 6: It will open a new window, where you can enter your current password to confirm and the new password that you want to set:
After entering your passwords, click on the change button on the window’s top right corner, as highlighted in the above screenshot.
Congratulations! Your password has been changed successfully using the GUI of CentOS. From here on out, you will have to use the new password to login into your account.
Method 2: Changing the User Password through Terminal
When you are using a CentOS 8 server only without a GUI, and you only have access to the terminal of the CentOS 8 Operating system, then the GUI method won’t work. We have to change the password using the terminal, and we can do so easily.
Step 1: First of all, open up the terminal of the CentOS 8 Operating system from the application menu.
Step 2: In the terminal, type the “passwd” command and press Enter to change the password:
You will be asked to input your current password:
If you have entered the correct, current password, it will ask you to input your new password:
Once you entered the new password that you want to set, it will ask you to confirm your new password:
The password will get changed if both passwords match, and a success message will appear on the terminal.
How to change another user’s Password in CentOS
The terminal will directly ask you to input the new password and confirm the new password:
You will get a success message:
Conclusion
As mentioned above, Data protection is a modern-day necessity. Data is now being labeled as a valuable commodity. Nowadays, it has become an absolute must to use unique, complicated, and strong passwords to protect your data.
About the author
A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.
Resetting Forgotten Root Password
If you have forgotten your password and after trying a lot to remember your old password, you are still unable to get that. Do not worry; we can reset the root password from the GRUB Boot Menu.
For resetting the root password, first, reboot your computer.
When the system restarts, press the “ESC” key immediately to interrupt the boot process.
Select the kernel from the GRUB/Boot menu you want to boot into by pressing the arrow keys.
Pressing ‘e’ from your keyboard will open the editing menu.
In the editing menu, locate the “ro” kernel parameter and replace it with “rw,” and add an additional parameter “init=/sysroot/bin/sh”:
Now run the “chroot /sysroot” command to convert the root file system in read and write mode:
You will now be able to change the root password.
To set a new password for root, input the command:
You will then be asked to input a new password and then confirm it. It is best to use a unique, complex, and complicated password that is easy to remember.
Once everything is changed and saved, reboot your computer by using the “reboot” command:
You may need to wait a few minutes to let the SELinux relabelling process complete.
Upon completion, the system will reboot, and the login screen will appear.
Resetting Root password from Terminal
If you need to reset your root password and know the current password, there is no need to do anything complex. Just fire up your CentOS 8 terminal and type the command given below:
Please do not select common words as your password.
Conclusion
In this article, we’ve learned how to reset a root password that is forgotten. Moreover, we also learned to set up a new root password if you remember your current password.
About the author
A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.
In this tutorial we’ll see how to restore the root password for CentOS in a very simple way.
To reset your CentOS root password you’ll need to reboot or turn off your computer. Then turn on your computer and when GRUB starts press e to edit the rules and then press enter.
Scroll down and look for the line containing ro crashkernel=auto or just ro part.
Replace ro crashkernel=auto or ro with rw init=/sysroot/bin/sh
Where:
ro = read only
rw = readable and writable
/sysroot/bin/ = OS system shell.
Make sure you edit the file properly otherwise the process will fail and you’ll need to repeat the previous steps.
Default file look:
The file must look like the screenshot below. After double checking you wrote it properly, press ctrl+x to save the changes.
Edited file look:
You’ ll get a root console from which you are able to set a new root password by running the commands below, make sure to set a password longer than 8 characters, don’t use weak passwords which may be included in brute force dictionaries or the OS may refuse it, combine numbers, characters and symbols to increase your security.
sysroot
root
Set your new password
And then
chroot /sysroot =access the OS.
passwd root = reset root password.
touch /.autorelabel = update selinux
exit = exit the OS
reboot
After restarting you will be able to login with the new password, now you can get back to work.
About the author
Read Also: How to Set Up Automatic Updates for CentOS 8 and How to Reset Forgotten Root Password in RHEL 8
Reset Forgotten root Password in CentOS 8
First, reboot or power on your CentOS 8 system. Select the kernel you want to boot into. Next, press ‘e’
on the keyboard to interrupt the boot process and make changes.

On the next screen, locate the ro
(read-only) kernel parameter as highlighted below.

Replace the kernel parameter ro
with rw
and append an extra kernel parameter init=/sysroot/bin/sh
. In a nutshell, simply replace the kernel parameter ro
with rw init=/sysroot/bin/sh
.

Next, run the command below to mount the root file system in read and write mode.
:/# chroot /sysroot

You can now change the root password by executing the command:
:/# passwd root
Provide a new root password and confirm it. For best practice select a password with a combination of uppercase, lowercase, numerical and special characters to boost password strength.

Next, run the command below to enable SELinux relabelling.
:/# touch /.autorelabel

To apply the changes, exit and reboot the CentOS 8 system.
:/# exit :/# reboot

Upon reboot, the SELinux relabelling process will commence. Give it about 3 minutes.

We hope this tutorial will be beneficial to you. Feel free to weigh in your feedback if you are stuck.

Well here is the guide which will take you out of any such situation if you ever get into it. Here in this article we will be taking you to the journey of resetting your RHEL 7 and CentOS 7 root password.
This very morning I turned my RHEL 7 Linux server to find out that it has been locked. Either I messed up with password I changed last night or I have really forgotten it.


After you press 'e'
from keyboard you would see a lot of text which may be clipped as per the size of your screen.

Search for the text “rhgb quiet”
and replace it with “init=/bin/bash”
without quotes.

Once done editing press 'ctrl+x'
and it will start booting with specified parameter. And you will get bash prompt.

# mount | grep root

You may notice that root partition is reported to be 'ro'
(Read Only). We need to have read-write permission on root partition to change the root password.
# mount -o remount,rw /
Also cross check, if the root partition is mounted with read-write permission mode.
# mount | grep root

Now you can change the root password by typing the passwd command. But that is not done. We need to relabel SELinux context. If we skip relabeling the whole SELinux context we would be able to login using using password.
# passwd root [Enter New Password] [Re-enter New Password]
# touch /.autorelabel

Reboot and login again to root account and see if everything works ok or not?
# exec /sbin/init
This article will guide you through simple steps to reset forgotten root password in RHEL-based Linux distributions such as CentOS 8 and Fedora 35/34.
Reset Forgotten Root Password in RHEL/CentOS & Fedora
First, restart your system, and at the boot grub menu choose the kernel (mostly the first option) you wish to boot into and press the key 'e'
on your keyboard.


On the next screen, you will land into emergency mode, here press Enter key to get into the shell prompt. Now, make sure to confirm that you remount the sysroot directory with read and write permissions. By default, it is mounted with read-only mode indicated as ro
.
# mount | grep sysroot

Now remount the sysroot directory with read and write permissions and confirm the permissions again. Note that this time, the permissions have changed from ro
(read-only) to rw
(read and write) as shown.
# mount -o remount,rw /sysroot/ # mount | grep sysroot

# chroot /sysroot
Next, use the passwd command to reset the root password with the new password and confirm it.
# passwd

# touch /.autorelabel

Finally, type exit and then log out to start the SELinux relabelling process.


And that’s how you would reset a forgotten root password in RHEL/CentOS 8 and Fedora 35/34 Linux distributions.
Open Terminal
You can open the application launcher search bar by pressing the window key or superscript key on the keyboard.
Log in as admin or root user
$ sudo -i
Step 3. Change the sudo password using the passwd command
$ passwd
Now use the newly updated password for your root account in all software installations and file configuration operations that require root authorization.
Log off or terminate the root terminal session
$ exit
After running the above command, the logout status will be displayed on the terminal, which means that you have now been logged out or exited from the root account.
Shortcut alternative
$ sudo passwd root
After running the above command, a password change notification will appear on the terminal. Now enter the new password and press “Enter”. Enter the newly selected password again and press “Enter” again. After that, a message will appear that all authentication tokens have been successfully updated, which means that the root password has been changed.
Posted by
on September 14, 2016
Normally resetting the root password is a simple task if you’re logged in already with root privileges, however if you forget the password and need to change it things become a little more difficult.
This is also a task that you will need to know how to perform for the RHCSA exam.
This procedure will be completed in the console of the Linux system, so be sure that you have access to this prior to beginning. As with all system maintenance tasks, be sure you have a system backup/snapshot prior to proceeding.
- If your Linux system is currently running, reboot it. If it is not yet running, start it up. At the boot menu, press the ‘e’ key to edit the first boot entry.
- From the grub options, find the line that starts with “linux16” and go to the end of it. Enter ‘rd.break’ without quotes at the end of this line, as shown below.
- Press “Ctrl+x” to boot with these options. This will boot to the initramfs prompt with a root shell.
- At this stage, the root file system is mounted in read only mode to /sysroot and must be remounted with read/write (rw) permissions in order for us to actually make any changes. This is done with the ‘mount -o remount,rw /sysroot’ command.
- Once the file system has been remounted, change into a chroot jail so that /sysroot is used as the root of the file system. This is required so that any further commands we run will be in regards to /sysroot. This is done by running ‘chroot /sysroot’.
- From here the root password can be reset with the ‘passwd’ command.
- If you’re not using SELinux, you could reboot at this point and everything would be fine, however by default CentOS/RHEL 7 use SELinux in enforcing mode, so we need to fix the context of the /etc/shadow file. This is because when the ‘passwd’ command is run, it creates a new /etc/shadow file. As SELinux is not running in this mode the file is created with no SELinux contexts, which can cause problems when we reboot. Create the /.autorelabel command using ‘touch’.
Creating this file will automatically perform a relabel of all files on next boot. Note that this may take some time depending on the amount of files you have on the file system. For a plain vanilla CentOS 7 server, it takes me about 2 minutes to complete.
- Enter the ‘exit’ command twice, the first one will exit the chroot jail environment while the second will exit the initramfs root shell and reboot the system.
Once the reboot has completed you will be able to use the root account with your newly set password.
Summary
As shown we can reset the root password in Linux CentOS/RHEL 7 by booting with the ‘rd.break’ option, remounting the file system with read/write privileges, creating a chroot jail, executing the passwd command and then finally fixing up SELinux contexts.
After exiting the chroot and the initramfs root shell prompt the file system will be relabelled which may take a few minutes or more depending on the number of files you have. When your system has booted back up you’ll be able to use the new root password.
Most of the time, the root account is disabled, meaning that you cannot access it.
However, you may want to access the root account sometimes to perform specific tasks.
In this tutorial, we will learn how you can change the root password on CentOS 8 easily.
Prerequisites
In order to change the root password on CentOS 8, you need to have sudo privileges or to have the actual password of the root account.
$ sudo -l User <user> may run the following commands on host-centos: (ALL : ALL) ALL
If this is the case, you should be able to change the root password.
If you installed CentOS 8 with the default settings, you may have chosen to lock the root account by default.
Please note that changing the root password will unlock the root account.
Change root password using passwd
The easiest way to change the root password on CentOS 8 is to run the passwd command.
$ sudo passwd Changing password for user root. New password: Retype new password: passwd: all authentication tokens updated successfully.
$ sudo passwd root
Recommendation : you should set a strong password for the root account. It should be at least 10 characters, with special characters, uppercase and lowercase letters. Also, it should not contain any words that are easily found in a dictionary.
In order to connect as root on CentOS 8, use the “su” command without any arguments.
$ su - Password: [root@localhost ~]#
Change root password using su
Alternatively, if you are not sudo you can still change the root password if you have the actual root password.
$ su - Password: root@host-centos:~#
Now that you are connected as root, simply run the “passwd” command without any arguments.
$ passwd Changing password for user root. New password: Retype new password: passwd: all authentication tokens updated successfully.
Conclusion
In this quick tutorial, you learnt how you can change the root password on CentOS 8 : by using the passwd command or by connecting as root and changing your password.
Setting the root password can be quite useful if you plan on setting up a SSH server on CentOS 8 for example.