How to Change the Root Password in Linux

Download ArticleDownload Article

This How.com.vn teaches you how to change the Linux root password if you have the current password or if you don't have access to the current root password.

Method 1
Method 1 of 2:

With the Current Root Password

Download Article
  1. How.com.vn English: Step 1 Open a terminal window.
    To do so, press Ctrl+Alt+T,[1] which will open a new terminal window with a command prompt in most Linux desktop environments.
    • If you’re not using a desktop environment, you’re already at a command prompt, so proceed to the next step.
  2. How.com.vn English: Step 2 Type su at the command prompt, and press ↵ Enter.
    [2] A Password: line will open below the command prompt.
    Advertisement
  3. How.com.vn English: Step 3 Type the current root password, then press ↵ Enter.
    When the password is accepted, you’ll be brought back to the command prompt as the root user.
    • If you type the password incorrectly, run su and try again.
    • Passwords are case-sensitive.
  4. How.com.vn English: Step 4 Type passwd and press ↵ Enter.
    An Enter new UNIX password: line will appear below the prompt.
  5. How.com.vn English: Step 5 Type a new password and press ↵ Enter.
    The password you type will not appear on the screen.
  6. How.com.vn English: Step 6 Retype the new password and press ↵ Enter.
    You will see a message that reads “password updated successfully.”
  7. How.com.vn English: Step 7 Type exit and press ↵ Enter.
    This will log you out of the root account.
  8. Advertisement
Method 2
Method 2 of 2:

Without the Current Root Password

Download Article
  1. How.com.vn English: Step 1 Restart your computer.
  2. How.com.vn English: Step 2 Press E at the Grub menu.
    [3] The Grub menu appears right after you turn on the computer. In most cases, it only stays on the screen for a few moments.
    • If you don’t press E before the Grub menu disappears, reboot and try again.
    • This method works for most popular Linux distributions (Ubuntu, CentOS 7, Debian). There are many distributions of Linux, some more obscure than others. If you’re not able to get to single-user mode with this method, check your distribution’s website for instructions specific to your system.
  3. How.com.vn English: Step 3 Scroll to the line that begins with linux     /boot.
    Use the and keys to do so. This is the line you’ll need to modify in order to boot into single-user mode.
    • In CentOS and some other distributions, the line may begin with linux16 rather than linux.
  4. How.com.vn English: Step 4 Move the cursor to the end of the line.
    Use the , , , and keys to place the cursor right after ro.
  5. How.com.vn English: Step 5 Type init=/bin/bash after ro.
    The end of the line should now look like this:
    ro init=/bin/bash.
    • Note the space between ro and init=/bin/bash.
  6. How.com.vn English: Step 6 Press Ctrl+X.
    This tells the system to boot directly to a root-level command prompt in single-user mode.
  7. How.com.vn English: Step 7 Type mount –o remount,rw / at the prompt and press ↵ Enter.
    This mounts the file system in read-write mode.
  8. How.com.vn English: Step 8 Type passwd at the prompt and press ↵ Enter.
    Since booting into single-user mode gives you root access, there’s no need to pass additional parameters to the passwd command.
  9. How.com.vn English: Step 9 Type a new root password and press ↵ Enter.
    The characters you type won’t be displayed on the screen. This is normal.
  10. How.com.vn English: Step 10 Retype the new password and press ↵ Enter.
    When the system confirms you’ve re-entered the same password, you’ll see a message that reads “password updated successfully.”
  11. How.com.vn English: Step 11 Type reboot –f and press ↵ Enter.
    This command reboots the system normally.
  12. Advertisement

Community Q&A

Search
Add New Question
  • Question
    How do I find the current password?
    How.com.vn English: 77Ecrivan
    77Ecrivan
    Community Answer
    If you have lost your current root password, you may need to use a password cracking tool to get it back. Depending on the strength of the password you set, this could be either very easy or very difficult. John the Ripper is a popular password cracking tool that might work for you.
  • Question
    I am facing an authentication failure problem even after using a valid password. What can be the reason?
    How.com.vn English: 77Ecrivan
    77Ecrivan
    Community Answer
    If you are certain that you are in fact using the correct password, then you may have been locked out. To check if your account is locked, open up the terminal and enter "passwd -S [user name]". This should present you with some numbers and letters, a date and your user name. At the end of this line, check to see if it says "(Password locked.)". You can unlock an account by running "passwd -u" in the terminal.
  • Question
    I have tried this. The first time it works well, but not the second. I notice my linux line does not have the /boot/, can it still work?
    How.com.vn English: Haxalicious
    Haxalicious
    Community Answer
    If your linux line does not have /boot/ and it does not boot up then you have broken your GRUB. You will need to re-add this line to boot your computer. If there is another path then just add the required things after "ro" on the linux line.
See more answers
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
      Advertisement

      Video

      Tips

      • To change the password for another user, su to root and type passwd <username>.
      • Your password should be 8 characters or more and contain a mix of letters (upper and lowercase), numbers and symbols.
      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Thanks for submitting a tip for review!
      Advertisement

      About This Article

      How.com.vn English: How.com.vn Staff
      Co-authored by:
      How.com.vn Staff Writer
      This article was co-authored by How.com.vn Staff. Our trained team of editors and researchers validate articles for accuracy and comprehensiveness. How.com.vn's Content Management Team carefully monitors the work from our editorial staff to ensure that each article is backed by trusted research and meets our high quality standards. This article has been viewed 5,280,272 times.
      How helpful is this?
      Co-authors: 17
      Updated: March 14, 2023
      Views: 5,280,272
      Categories: Linux
      Article SummaryX

      1.Type "su" and press Enter.
      2.Enter the current password and press Enter.
      3.Type "passwd '" and press Enter.
      4.Confirm the new password and press Enter.
      5.Type "exit" and press Enter.

      Did this summary help you?

      Thanks to all authors for creating a page that has been read 5,280,272 times.

      Is this article up to date?

      ⚠️ Disclaimer:

      Content from Wiki How English language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
      Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.

      Notices:
      • - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
      • - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
      • - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
      • - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.

      Advertisement