The root account is a special user account on Linux that has access to all files, all commands and that can pretty much do anything on a Linux server.
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.
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.
Alternatively, you can specify the root user account with the passwd command.
$ 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.
First, make sure to switch user to root by running the “su” command without any arguments.
$ 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.
You can now leave the root account by pressing “Ctrl +D”, you will be redirected your main user account.
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.
Using the root account can also be quite useful if you plan on adding and deleting users on your CentOS 8 server.
If you are interested in Linux system administration, we have a complete section dedicated to it on the website, so make sure to check it out.