How to Change Root Password in Ubuntu Linux

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

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

restart or change root password in linux
  • A computer running Linux
  • Command-line interface (terminal)

Содержание
  1. Introduction
  2. Temporary Switching to root
  3. Changing Root Password
  4. Conclusion
  5. How to Reset the Root Password on Debian 9 Stretch
  6. Installing and Configuring sudo
  7. Setting Root Password
  8. Changing Root Password
  9. Disabling Root Login
  10. Recovering Lost Root Password
  11. About the author
  12. Option 1: Changing Ubuntu Password in the Command Line
  13. Option 2: Change sudo Password with the passwd Command
  14. Option 3: Changing Ubuntu Password Using GUI
  15. 1: Change root Password with sudo Permission
  16. 2: Change root Password with root Permission
  17. 3: Change root Password Using GUI
  18. Conclusion
  19. About the author
  20. Change or Reset Root Password as Sudo User
  21. Change or Reset Root Password Using GRUB Menu
  22. Conclusion
  23. About the author
  24. See Password Status Info
  25. See Password Status Info for All the Accounts
  26. Change a User Password
  27. Delete User Password
  28. Expire Account Password
  29. Set Number of Days After the Password Expires and the Account Deactivates
  30. Set the Minimum Number of Days Between Password Changes
  31. Set the Maximum Number of Days for Which the Password Remains Valid
  32. Change the Expired Password
  33. Display the Warning for Expiring Password
  34. Lock the Password
  35. Unlock the Password of an Account
  36. Use the Quiet Mode
  37. Change Password for Repository Named “Repo”
  38. Change the Root Directory for the passwd Command Process
  39. See All passwd Commands
  40. Changing Your Root Password in Ubuntu
  41. Step 1: Open a Terminal Window
  42. Step 2: Change Your Root Password
  43. Resetting a Root Password in Ubuntu
  44. Step 1: Boot to Recovery Mode
  45. Step 2: Drop Out to Root Shell
  46. Step 3: Remount the File System with Write-Permissions
  47. Step 4: Change the Password
  48. Changing the Root Password in CentOS
  49. Step 1: Access the Command Line (Terminal)
  50. Step 2: Change the Password
  51. Step 1: Access Boot Menu
  52. Step 2: Edit Boot Options
  53. Step 3: Remount the Drive
  54. Step 4: Changing the Password
  55. Step 5: Restart

Introduction

Temporary Switching to root

sudo command-name
sudo su -
whoami
Output

root

Changing Root Password

sudo passwd root

The new root password will be required to be entered and confirmed.

Make sure you use a strong and unique password when creating the password. The most critical part of your account’s security is having a strong password. A strong password often consists of at least 16 characters, one uppercase letter, one lowercase letter, one number, and one special character.

When you type the password, it does not appear on the screen.

Output

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

That’s it. The password for the root account has been updated.

You can now use the new password to log in to your Ubuntu system as root.

Conclusion

The root account in Ubuntu has no password by default. To run commands with root capabilities, the sudo command is advised.

You’ll need to set the root password before you can log in as root.

If you have any queries, please leave a comment below and we’ll be happy to respond to them.

How to Reset the Root Password on Debian 9 Stretch

In this article, I will show you how to configure sudo, set root password, disable root login and reset root password. This can be done even if you don’t have sudo enabled and you don’t remember the password.  Let’s get started.

Installing and Configuring sudo

How to Change Root Password in Ubuntu Linux

Now type in your root password and press <Enter>.

How to Change Root Password in Ubuntu Linux

How to Change Root Password in Ubuntu Linux

The apt package repository cache should be updated.

How to Change Root Password in Ubuntu Linux

How to Change Root Password in Ubuntu Linux

It should be installed. In my case it is already installed.

How to Change Root Password in Ubuntu Linux

How to Change Root Password in Ubuntu Linux

How to Change Root Password in Ubuntu Linux

How to Change Root Password in Ubuntu Linux

How to Change Root Password in Ubuntu Linux

The command should run as root as you can see from the screenshot below.

How to Change Root Password in Ubuntu Linux

Setting Root Password

How to Change Root Password in Ubuntu Linux

How to Change Root Password in Ubuntu Linux

Now type in your desired root password and press <Enter>.

How to Change Root Password in Ubuntu Linux

Now retype the root password and press <Enter>.

How to Change Root Password in Ubuntu Linux

The root password should be set. Now you can login as root using your root password.

How to Change Root Password in Ubuntu Linux

Changing Root Password

Now do the same things as you did on the Setting Root Password section of this article.

Disabling Root Login

How to Change Root Password in Ubuntu Linux

Recovering Lost Root Password

If you happen to forget the root password and you don’t have sudo configured, then don’t give up just yet and think about reinstalling the operating system again. There is a way to reset the root password.

First reboot your computer. You should see the GRUB menu when your computer boots as shown in the screenshot below. Select Debian GNU/Linux and press e.

How to Change Root Password in Ubuntu Linux

How to Change Root Password in Ubuntu Linux

Now remove ‘ro quiet’ part from the end of the line and append ‘init=/bin/bash’ to the end of the line as marked in the screenshot below. Once you’re done, press F10.

How to Change Root Password in Ubuntu Linux

How to Change Root Password in Ubuntu Linux

How to Change Root Password in Ubuntu Linux

remount,rw proc

How to Change Root Password in Ubuntu Linux

How to Change Root Password in Ubuntu Linux

Now type in your new root password and press <Enter> to continue.

How to Change Root Password in Ubuntu Linux

Now re-type your new root password and press <Enter> to continue.

How to Change Root Password in Ubuntu Linux

You root password should be changed.

How to Change Root Password in Ubuntu Linux

Now press <Ctrl> + <Alt> + <Delete> and your Debian 9 Stretch machine should reboot.

Now you can login as root with your new root password as you can see in the screenshot below.

Дополнительно:  Android root and shell root

How to Change Root Password in Ubuntu Linux

How to Change Root Password in Ubuntu Linux

This is how you reset your root password on Debian 9 Stretch. Thanks for reading this article.

About the author

Are you looking to change the root password in Ubuntu?

Changing passwords is a good practice and should be done periodically.

There are three (3) ways to change passwords in Ubuntu.

The first two (2) options use the command line, and the other uses Linux’s graphical interface (GUI).

  • Ubuntu installed and running
  • A user with sudo privileges
  • Access to a terminal/command line
  • The apt-get tool, pre-loaded in Ubuntu and other Debian-based distros

Option 1: Changing Ubuntu Password in the Command Line

To change the sudo password using the sudo command:

1. First, open the terminal using the keyboard shortcut CTRL+ALT+T.

2. Query for a password change by running the command:

sudo passwd root

You will be prompted to enter and verify a new password. The output will inform you the password was updated successfully.

example output after ubuntu changing root password
image of terminal to exit changes after password reset

Option 2: Change sudo Password with the passwd Command

1. First, open the terminal (CTRL+ALT+T).

sudo –i

Type in your current password and hit Enter. The output you receive should show that you can now run commands as root.

example command for sudo -l

3. Next, change the password by running the command:

passwd

Type and retype a new password to verify the change.

exit

5. Exit out of the terminal with the same command:

exit

Option 3: Changing Ubuntu Password Using GUI

To change the default root password in Ubuntu without using the terminal or any commands, use the graphical interface.

1. Open the Activities overview by pressing the Windows or Super key.

2. Type settings in the search bar and click on the Settings icon.

3. In Settings, click on the Details card (which is most likely the last one).

example of Ubuntu graphical interface with details selected

5. This will open a new Change Password pop-up. Type in your current root password, your new root password and verify the new password by retyping it.

6. Once you have filled in all the fields, click Change to confirm the changes.

change password prompt in ubuntu

Finally, make sure that your password includes both lower and upper case letters, numbers and special characters. It is essential to have a strong password to prevent brute force attacks.

However, to avoid security attacks, it is necessary to change the root password regularly. Because resetting the password time to time helps you to get rid of these issues, even if your ex-team member finds your old password, they wouldn’t be able to access the system.

We have two most common ways to change root password on Linux Mint 21 system:

1: Change root Password with sudo Permission

How to Change Root Password in Ubuntu Linux

In the next move, you will be asked to type the new root password for the Linux mint system:

How to Change Root Password in Ubuntu Linux

Re-enter the new root password you have set above for confirmation:

How to Change Root Password in Ubuntu Linux

Once both passwords match, you will get a message on terminal that you have successfully updated Linux Mint root password.

How to Change Root Password in Ubuntu Linux

2: Change root Password with root Permission

For this method, you should have changed the root password of the Linux Mint system at least one time before. And, you must know the current sudo password to gain root privileges. So, execute the mentioned command and type the current root password of your Linux system:

How to Change Root Password in Ubuntu Linux

In the next command, execute the ‘passwd’ command to the terminal for further process. This will allow you to modify the root password:

How to Change Root Password in Ubuntu Linux

Type the new password you want to set, and hit Enter:

How to Change Root Password in Ubuntu Linux

Re-enter the password you have set above. You will receive a successfully updated message if the password is entered correctly:

How to Change Root Password in Ubuntu Linux

3: Change root Password Using GUI

How to Change Root Password in Ubuntu Linux

Type the current root password and click to Authenticate button:

How to Change Root Password in Ubuntu Linux

How to Change Root Password in Ubuntu Linux

Once you clicked, a dialogue box of Change Password will be appeared on the screen:

How to Change Root Password in Ubuntu Linux

Type the new password of your choice in the New Password entry and re-write it on the Confirm Password tab. If your passwords match, then hit to Change button:

How to Change Root Password in Ubuntu Linux

The root password of the Linux Mint 21 system has changed successfully.

Conclusion

Through this guide, we have learned how to change the root password on Linux Mint 21 system. We have done it using two different approaches, one approach leads to CLI which includes sudo and root permissions. And in the second approach, we used the GUI method.

About the author

I am a Software Engineer Graduate and Self Motivated Linux writer. I also love to read latest Linux books. Moreover, in my free time, i love to read books on Personal development.

But what do you do if the root password must be modified or reset?

This article shows you how to change the root password for your Linux Mint 20 system via three different methods.

Note: To change the root password, you must have either the current root password, sudo privileges, or have physical access to the system. It is also recommended to save the new password(s) in a secure location to be accessed when needed.

In this article, we will cover how to:

  1. Change or reset root password as root user
  2. Change or reset root password as sudo user
  3. Change or reset root password using GRUB menu
Дополнительно:  Как дать user права root

It is worth mentioning that all the commands included in this article have been tested in the Linux Mint 20 system. These commands have been performed in the Terminal, which can be opened using the Ctrl+Alt+T key shortcut, or by clicking on the terminal icon present in the taskbar of the Linux system.

You will be prompted to enter a new root password. Type the new password and hit the Enter key. Then, re-enter the password and press the Enter key to avoid any typos.

After entering the password, you will be shown a message saying that the password has been updated successfully.

How to Change Root Password in Ubuntu Linux

Change or Reset Root Password as Sudo User

After entering the password, you will be shown a message saying that the password has been updated successfully.

How to Change Root Password in Ubuntu Linux

Change or Reset Root Password Using GRUB Menu

Next, navigate to the Advanced options.

How to Change Root Password in Ubuntu Linux

Then, to switch to the edit window, click ‘e’ on the keyboard.

How to Change Root Password in Ubuntu Linux

How to Change Root Password in Ubuntu Linux

“linux bootvmlinuz-5.4.0—generic ==\2d26aa-051e
ro quiet splash”

How to Change Root Password in Ubuntu Linux

Replace ‘ro‘ with ‘rw’ in the above line and, at the end of the line, append ‘init=/bin/bash’. It should now look like this:

“linux bootvmlinuz-5.4.0—generic ==\
2d26aa-051e-4dbe-adb2-7fbb843f6581 rw quiet splash =bin”

Adding ‘rw’ and ‘init=/bin/bash’ in the above line basically tells the system to log in to bash with read/write privileges. Note that this configuration will only apply for the current boot, not for subsequent boots.

How to Change Root Password in Ubuntu Linux

How to Change Root Password in Ubuntu Linux

You will be prompted for the root password. Input the root password and press the Enter key. Then, retype the password and press Enter to avoid any typos.

After entering the password, you will then see a message stating that the new password has been updated.

How to Change Root Password in Ubuntu Linux

That is all you need to do to change or reset the root password of your Linux Mint 20 system without the sudo or root login. It is good practice to change the password frequently after some time, especially if you think it has been compromised.

Conclusion

In this article, we have identified three different methods to modify or reset the root password on your system. You can opt for any method, based on the privileges you have. If you have the root password or sudo privileges, you can easily reset the root password using the simple ‘passwd’ command. Otherwise, you can use the GRUB menu to change the root password, but only if you have physical access to the system.

I hope this article has helped you in changing or resetting the root password of your system.

About the author

I am a self-motivated information technology professional with a passion for writing. I am a technical writer and love to write for all Linux flavors and Windows.

This article shows examples of how to use the passwd command in Linux, along with all the available options.

How to Use the passwd Command in Linux
  • Access to the terminal
  • Superuser or root privileges (sudo)

Note: To check if you have sudo privileges, type sudo whoami in the terminal.

The general command is:

passwd <options> <username>
Terminal output of the passwd command

See Password Status Info

Using passwd with the --status option displays all the information about a password and the validity periods. The shorter version is -S:

passwd --status
passwd -S
Terminal output of passwd -S command
sudo passwd -S <username>

The password status has seven fields:

The last three fields are in days.

See Password Status Info for All the Accounts

Check the status info for all accounts using passwd with the sudo command with the -S and -a options, or the extended version --all:

sudo passwd --status --all
sudo passwd -S -a

Change a User Password

sudo passwd <username>

Delete User Password

sudo passwd --delete <username>
sudo passwd -d <username>

When you check the password status, it changes the second field from P to NP:

Terminal output of using the command passwd -d

The passwd --delete and passwd -d commands are a quick way to disable a password for an account.

Expire Account Password

To force expire a password use the --expire or -e options with the passwd command:

sudo passwd --expire <username>
sudo passwd -e <username>
Terminal output of the command passwd -e

Set Number of Days After the Password Expires and the Account Deactivates

An account can automatically deactivate after its password has expired and not changed for a certain number of days. Use the -i or --inactive option and set the number of days as an integer:

sudo passwd --inactive <number of days> <username>
sudo passwd -i <number of days> <username>
Terminal output of the command passwd -i

Set the Minimum Number of Days Between Password Changes

To change the minimum number of days between password changes, use the --mindays or -n option with the number of days as an integer:

sudo passwd --mindays <number of days> <username>
sudo passwd -n <number of days> <username>
Terminal output of the command passwd -n

Set the Maximum Number of Days for Which the Password Remains Valid

To change the maximum number of days between password changes, use the --maxdays or -x option with the number of days as an integer:

sudo passwd --maxdays <number of days> <username>
sudo passwd -x <number of days> <username>
Terminal output of the command passwd -x

Change the Expired Password

Once a password expires, a prompt appears during next login to change the password. Enter the old password and then a new one twice for confirmation. In this example, the expiry was root enforced:

Дополнительно:  Что это 404 ошибка и как её исправить?
Terminal prompt for password change

Display the Warning for Expiring Password

The warning period message displays for expiring passwords. Use the option --warndays or -w to set how many days before the expiry the warning appears:

sudo passwd --warndays <number of days> <username>
sudo passwd -w <number of days> <username>
Terminal output of the command passwd -w

Lock the Password

sudo passwd --lock <username>
sudo passwd -l <username>
Terminal output of command passwd -l

Unlock the Password of an Account

To unlock a password for a locked account (L), use the --unlock or -u option:

sudo passwd --unlock <username>
sudo passwd -u <username>
Terminal output of the command passwd -u

Use the Quiet Mode

passwd --quiet
passwd -q
Terminal output of command passwd -q

Change Password for Repository Named “Repo”

sudo passwd --repository <repository> <username>
sudo passwd -r <repository> <username>
Terminal output of the command passwd -r

Change the Root Directory for the passwd Command Process

The passwd command process runs from the default root directory. Modify the root directory by running the --root option:

sudo passwd --root <directory path>

Or the -R option:

sudo passwd -R <directory path>

You need to set a password for root for the information update.

Terminal output of the command passwd -R

See All passwd Commands

There are numerous commands to use with the passwd tool. List all the options if you forget any by running:

passwd --help
passwd -h

A list of all the options along with a short description prints out:

Terminal output of the command passwd -h

If you find it hard to keep track of all the different passwords and changes, there are many enterprise solutions for password management.

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 Menu > Applications > Accessories > Terminal.

Step 2: Change Your Root Password

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 terminal command

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.

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 system. 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
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.

Note: Learn how to use the chpasswd command. Chpasswd is helpful for managing multiple passwords and making multiple changes.

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

sudo passwd root
change root password in centos

This is a similar process as in Ubuntu, with a couple of variations.

Step 1: Access Boot Menu

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

Step 2: Edit 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.

Step 3: Remount the Drive

mount / -o remount,rw

Step 4: Changing the Password

passwd

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

Step 5: Restart

mount / -o remount,ro
sync
reboot

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

Note: If you ever come across a Linux boot failure, be sure to save our guide on using GRUB rescue to troubleshoot it.

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.

Оцените статью
Master Hi-technology
Добавить комментарий