Introduction

In Linux, root privileges (or root access) refers to a user account that has full access to all files, applications, and system functions.

Most basic Linux user accounts run with limited privileges. This keeps users from making mistakes or accidentally running malicious software.

To use protected operating system features, a Linux user has to temporarily elevate their privileges using a command like sudo. The sudo command tells the system to run a command as a superuser, or a root user. When you run a function using sudo, you’ll usually have to enter your password.

Some versions of Linux will elevate your user privileges for a set amount of time around (15 minutes) before reverting. Other versions only perform a single task with elevated privileges.

It’s a good idea to change your passwords regularly, consider using enterprise password management software.

This guide will help you change your Linux root password in Ubuntu or CentOS, or reset the password.

reset or change root password in linux

Prerequisites

  • A computer running Linux
  • Command-line interface (also known as the Terminal)

Changing your root password in Ubuntu

Step 1: Open a terminal window

Right-click the desktop, then left-click “Open in terminal.

Alternately, you can click the Menu > Applications > Accessories > Terminal

Step 2: Change your root password

In the terminal window, type the following:

sudo passwd root

The system will prompt you to enter your password – this is the same password you use to log in to the system.

Next, the system will prompt you to enter a new password. Do so, and then re-enter it exactly the same when the system prompts you to retype the password. This double-entry confirms that you have typed the password correctly.

change root password in ubuntu

Resetting a root password in Ubuntu

In some situations, you may need to access an account for which you’ve lost or forgotten a password.

Step 1: Boot to recovery mode

Restart your system.  Once you see the splash screen for the computer manufacturer, hold down the shift key.  The system should come up with a black and white GRUB, or boot menu, with different Linux kernel versions displayed.  Select the second one from the top – the highest revision, followed by (recovery mode).  Press Enter.

Step 2: Drop out to root shell

The system should display a menu with different boot options.  Use the arrow keys to navigate to the option labeled root and press Enter.

The system should respond by giving you a command line interface with a prompt.

Step 3: Remount the file system with write-permissions

Right now, your system only has read-only access to your hard drive.  That means it can look at the data, but cannot make any changes.  But we need write-access to change the password, so we’ll need to remount the drive with the appropriate permissions.  At the prompt, type:

mount –o rw,remount /

Press Enter.  This should allow you to make changes to the data on the hard drive.

Step 4: Change the password

At the prompt, type:

passwd username

Substitute the name of the user for username, then press Enter. The system should ask you to type a new UNIX password, then retype it.

Once you’ve entered and confirmed the new password, reboot the system by entering the following:

shutdown –r

Hit enter, and your system should restart. Don’t press any keys, let the system come up to the login screen, and test to make sure the new password works.

Changing the root password in CentOS

Changing a password in CentOS is almost identical to changing it in Ubuntu.

Step 1: Access the command line (terminal)

Right-click the desktop, then left-click “Open in Terminal.”  Or, click Menu > Applications > Utilities > Terminal.

Step 2: Change the password

At the prompt, type the following, then press Enter:

sudo passwd root

The system should prompt you to enter your existing password.  Do so, then follow the prompts to enter and confirm a new root password.

change root password in centos

Reset the root password in CentOS

This is a similar process as Step B, with a couple variations.

Step 1: Access the boot menu

Restart the system, then tap the Esc key about once per second to launch the GRUB menu.

Step 2: Edit the boot options

Use the arrows to highlight the version of Linux you boot into, then press e.

Use the arrows to highlight the line that starts with kernel or Linux.

Press E.

At the end of the line, add a space then type single.  Press enter, then boot into single user mode by pressing Ctrl-X or B.  (The system will display the command to use.)

Step 3: Remount the drive

You should have a command line, and you’ll have root privileges.  To enable read/write access on your hard drive, type the following:

mount / -o remount,rw

Step 4: Change the password

Type the following:

passwd

Press enter, and the system should prompt you to enter and confirm a new password.

Step 5: Restart

Type the following, pressing enter after each line:

mount / -o remount,ro
sync
reboot

Your system should restart. Confirm that your new password works by logging in.

Conclusion

If you already have access to your user account, resetting or changing your password in Linux is simple.

It can be more challenging if you’ve lost or forgotten a password, but with a little creative restarting and editing, you shouldn’t find it too hard.