How to Change root Password on Linux
The root account has the ability to control anything on a Unix system, and Linux is no different. One has to use the passwd command to change Linux password data, and the same goes for root. Due to the special nature of this command, some precautions do apply. Notably, it’s not possible to change Linux password data for the root user readily on an Ubuntu or Ubuntu spin system without first making some changes.
A majority of users who want to change Linux password data will need to open a graphical terminal. You can hold down Ctrl, Alt and T to do so or perhaps click on the Applications menu, head to system tools and select terminal. CentOS users who don’t have a graphical interface installed will want to log into their virtual terminal with a user account, assuming they have the sudo packages updated.
Method 1: Change root Password on Most Linux Distributions
Assuming your distribution has the sudo package installed, you can change the root passwd with the sudo passwd root command. You’ll be asked for your sudo password first, and then you’ll have to enter a new UNIX password twice. Your password will be tested for complexity, so you’ll want to make sure that it’s good. Once you’ve entered the password in twice, your root account should be changed. Hold down Ctrl and Alt then push F1-F6 to get to an empty virtual terminal. Type root and then the new password to make sure it works. Considering the hazards related to working as root, make sure to type exit to get out of this console. Hold down Ctrl, Alt and F7 to get back to your graphical environment if you’re not working from a server. This method should work on Debian and many other distributions. It should also work with Arch if you have the all the prerequisite packages installed.
Method 2: Change root Password on Ubuntu Linux
Ubuntu and its various derivatives hash out the root account, which functionally disables it. You won’t be able to readily change out the password of the root user because it doesn’t really exist. This is true for Xubuntu, Kubuntu, Lubuntu and potentially most installations of Linux Mint and Trisquel. While it’s possible to activate the account, it’s not at all recommended. Keep in mind that your first user on these systems is an administrator and can access a root account by typing sudo -i at the prompt and entering your password. This works the same as any other root login, and it’s a good bit safer. If you’re absolutely certain that you want to activate the root account and understand the risks involved, then type sudo passwd root and push enter. Enter a new UNIX password and make sure you don’t forget it. You’ll then need to run sudo passwd -u root to unlock your account. You’ll get a message that reads something like “password expiry information changed,” which means you’ve opened the account. The root user will work like normal, but please keep in mind just how dangerous this actually is. When you want to disable the root account, you can type sudo passwd -dl root to lock it up again.
Method 3: Change Linux Password Data as root
If you’re logged in as root say on a CentOS, Fedora or Red Hat Enterprise Linux server’s virtual terminal, then you can change the password simply by typing passwd and then pushing enter. You’ll receive a prompt that reads “Enter new UNIX password:” and then you’ll be asked to type it a second time. Keep in mind that you should have actually logged into root in order to do this, or perhaps used sudo su to access a root prompt. This won’t work on an unaltered Ubuntu or Linux Mint system, but it’s good for those running server systems or using ssh to log into ones remotely. Make sure before you try this that you have # as the symbol in your prompt. Depending on the default login shell set for root, the prompt may have other bits of information in it.
Remember that regardless of what method or which distribution you’re working on, you can also type whoami and push enter to find out who you’re logged in as.