Download Article
A step-by-step guide to get admin power on your Linux system
Download Article

The "root" user account on Linux has full administrative privileges over the entire system. If you want to edit system configuration files, install software, add users, or virtually anything else outside of your home directory, you'll need root access. For most tasks, you won't need to log or switch to the root user account—you can run your administrative tasks with the sudo command to run them as root. This prevents you from doing damage while logged in with full superuser permissions. If you're using Ubuntu, the root account is locked by default to prevent this from happening. But if you need to keep root access while doing a large amount of system tasks, you can enable the root user and become root with the su command, or by signing in as root on console.[1] This How.com.vn teaches you how to enable the Linux root user and gain root access.

How do you use Linux as root?

Pull up your Terminal, enter "sudo passwd root" and hit "Enter." Provide your user password, and then set a new password. Type it in twice to activate the root account.

Part 1
Part 1 of 5:

Unlocking the Root Account

Download Article
  1. How.com.vn English: Step 1 Open the terminal.
    Ubuntu and several other distributers lock the root account automatically to prevent you from using commands that can damage your system. You can unlock the root account in the terminal. If you're in the desktop environment, you can press 'Ctrl + Alt + T to start the terminal.[2]
  2. How.com.vn English: Step 2 Type .
    sudo passwd root and press Enter. When prompted for a password, enter your user password.[3]
    Advertisement
  3. How.com.vn English: Step 3 Set a new password.
    You'll be prompted to create a new password and enter it twice. Once a password has been set, the root account will be active.[4]
  4. How.com.vn English: Step 4 Lock the root account again.
    If you want to lock the root account, enter the following command to remove the password and lock root:
    • sudo passwd -dl root
  5. Advertisement
Part 2
Part 2 of 5:

Gaining Root Access in the Terminal

Download Article
  1. How.com.vn English: Step 1 Open the terminal.
    If the terminal is not already open, open it. Many distributions allow you to open it by pressing Ctrl + Alt + T.[5]
  2. How.com.vn English: Step 2 Type .
    su - and press Enter. This will attempt to log you in as "super user." You can actually use this command to log in as any user on the machine, but when left blank it will attempt to log in as root.[6]
  3. How.com.vn English: Step 3 Enter the root password when prompted.
    After typing "su -" and pressing Enter. You'll be prompted for the root password.[7]
    • If you get an "authentication error" message, your root account is likely locked. You will need to unlock the root account.
  4. How.com.vn English: Step 4 Check the command prompt.
    When you are logged in as root, the command prompt will end with # instead of $ (if you're using the bash, bourne, or korn shell) or % (if you're using csh, tcsh, or zsh).
  5. How.com.vn English: Step 5 Enter the commands that require root access.
    Once you've used su - to log in as root, you can run any commands that require root access. The su command is preserved until the end of the session, so you don't need to keep re-entering the root password every time you need to run a command.
  6. How.com.vn English: Step 6 Consider using .
    sudo instead of su -. sudo ("super user do") is a command that lets you run other commands as root temporarily. This is the best way for most users to run root commands, as the root environment is not maintained, and the user doesn't need to know the root password. Instead, the user will enter their own user password for temporary root access.[8]
    • Type sudo command and press Enter (e.g. sudo ifconfig). When prompted for the password, enter your user password, not the root password.
    • sudo is the preferred method for distributions like Ubuntu, where it will work even when the root account is locked.
    • This command is limited to users with administrator privileges. Users can be added or removed from /etc/sudoers.
  7. Advertisement
Part 3
Part 3 of 5:

Allowing Root Login (Ubuntu)

Download Article
  1. How.com.vn English: Step 1 Open the terminal.
    Ubuntu and several other distributers lock the root account automatically to prevent you from using commands that can damage your system. You can unlock the root account in the terminal. If you're in the desktop environment, you can press 'Ctrl + Alt + T to start the terminal.[9]
  2. How.com.vn English: Step 2 Type sudo nano /etc/gdm3/custom.conf and press ↵ Enter.
    This command allows you to edit the "custom.conf" file so that you can log in as the root account in the login page when you start your computer.[10]
  3. How.com.vn English: Step 3 Enter your user password and press ↵ Enter.
    Before you can edit the "custom.conf" file, Ubuntu asks you to enter your user password. Enter your password and press Enter..
  4. How.com.vn English: Step 4 Add AllowRoot=True to the file.
    Go to the bottom of the file. Add "AllowRoot=True" below "TimedLoginDelay = 10."[11] Add a few spaces so that the "A" in "AllowRoot" goes right below the "T" in "TimedLoginDelay".
  5. How.com.vn English: Step 5 Press Ctrl+X.
    This displays a prompt that asks if you want to save the file.
  6. How.com.vn English: Step 6 Press Y followed by ↵ Enter.
    This saves the "Custom.conf" file. You should return to the normal Terminal prompt.
  7. How.com.vn English: Step 7 Type sudo nano /etc/pam.d/gdm-password and press ↵ Enter.
    This is the command to edit the password authentication manager file.[12]
  8. How.com.vn English: Step 8 Enter your password and press ↵ Enter.
    Before you can edit the file, you are required to enter your user password. Enter your password and press Enter to continue.
  9. How.com.vn English: Step 9 Place a # on the third line.
    The third line says "auth required pam_succeed_if.so user != root quiet_success." Simply place a hashtag (#) at the beginning of this line. The entire line should turn blue. This enables root log in using the root password.[13]
  10. How.com.vn English: Step 10 Press Ctrl+X.
    This displays a prompt that asks if you want to save the file.
  11. How.com.vn English: Step 11 Press Y followed by ↵ Enter.
    This saves the "custom.conf" file. You should return to the normal Terminal prompt.[14]
  12. Advertisement
Part 4
Part 4 of 5:

Logging as Root

Download Article
  1. How.com.vn English: Step 1 Consider using other methods for gaining temporary root access.
    Logging in as root is not recommended for regular use, as it is very easy to perform commands that will render your system inoperable, and it also poses a security risk, especially if you are running an SSH server on your machine. Only log in as root when performing emergency repairs, such as dealing with disk failures or restoring locked accounts.
    • Using sudo or su instead of logging in as root will help prevent unintended damage while logged in as root. Using these commands gives the user a chance to think about the command before severe damage is done.
    • Some distributions, such as Ubuntu, leave the root account locked until you manually unlock it. Not only does this prevent users from unknowingly doing too much damage using the root account. It also secures the system from potential hackers, as the root account is typically targeted first. With a locked root account, hackers aren't able to gain access to it. You will need to unlock the root account and allow root login before logging in to the root account.
  2. How.com.vn English: Step 2 Enter .
    root as the user when logging into Linux. If the root account is unlocked and you know the password, you can log in as root when you're prompted to log in with a user account. Enter "root" as the user when prompted to log in.
    • If "root" is not listed as one of the log in accounts, click Not listed? and type "root" as the username.
    • If you need root access to perform a command, use the method in the previous section.
  3. How.com.vn English: Step 3 Enter the root password as the user password.
    After entering root as the username, enter the root password when prompted.
    • In many cases, the root password may be "password."
    • If you don't know the root password, or have forgotten it, see the next section for instructions on resetting it.
    • In Ubuntu, the root account is locked and cannot be used until it has been unlocked.
  4. How.com.vn English: Step 4 Avoid running complex programs while logged in as root.
    There's a chance that the program you intend to run will have a negative effect on your system when it has root access. It's highly recommended that you use sudo or su to run programs instead of logging in as root.
  5. Advertisement
Part 5
Part 5 of 5:

Resetting the Root or Admin Password

Download Article
  1. How.com.vn English: Step 1 Reset the root password if it has been forgotten.
    If you've forgotten the root password and your user password, you'll need to boot into recovery mode in order to change them. If you know your user password and need to change the root password, just type sudo passwd root, enter your user password, then create a new root password.
  2. How.com.vn English: Step 2 Reboot your computer and hold left-.
    Shift after the BIOS screen. This will open the GRUB menu.
    • The timing on this can be tricky, so you may have to try multiple times.
  3. How.com.vn English: Step 3 Select the first .
    (recovery mode) entry on the list. This will load recovery mode for your current distribution.
  4. How.com.vn English: Step 4 Select the .
    root option from the menu that appears. This will start the terminal with you logged in as the root account.
  5. How.com.vn English: Step 5 Remount the drive with write permissions.
    When you boot into recovery mode, you will typically only have read permissions. Enter the following command to enable write access:[15]
    • mount -rw -o remount /
  6. How.com.vn English: Step 6 Create a new password for any accounts you're locked out of.
    Once you're logged in as root and have changed the access permissions, you can create a new password for any account:[16]
    • Type passwd accountName and press Enter. If you need to change the root password, type passwd root.
    • Enter the new password twice when prompted.
  7. How.com.vn English: Step 7 Reboot your computer after resetting passwords.
    Once you're finished resetting passwords, you can reboot and use your computer as normal. Your new passwords will take effect immediately.[17]
  8. Advertisement

Community Q&A

Search
Add New Question
  • Question
    How can I make a user a superuser?
    How.com.vn English: Community Answer
    Community Answer
    Type in "sudo usermod -aG sudo " replacing the username of the user you want to grant superuser access.
  • Question
    How do we log in as a root in Method 3? I have my admin account and my guest account. Do I have to log as a root in terminal first?
    How.com.vn English: Community Answer
    Community Answer
    Yes. The root account must be unlocked first if you're using Ubuntu. Follow the instructions in method two. If you're not using Ubuntu, check your distribution's documentation.
  • Question
    What is the tilde used for?
    How.com.vn English: Community Answer
    Community Answer
    It designates a home folder (typically aliased to the current user's home folder).
See more answers
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
      Advertisement

      Tips

      Tips from our Readers

      • Make sure to lock the root account every time you've committed the changes you need.
      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Thanks for submitting a tip for review!

      Warnings

      • Only use the root account when you have to, and log out as soon as you are done.
      • Only share your root password with people who are A) trusted, and B) need to know it.
      Advertisement

      About This Article

      How.com.vn English: Travis Boylls
      Written by:
      How.com.vn Technology Writer
      This article was co-authored by How.com.vn staff writer, Travis Boylls. Travis Boylls is a Technology Writer and Editor for How.com.vn. Travis has experience writing technology-related articles, providing software customer service, and in graphic design. He specializes in Windows, macOS, Android, iOS, and Linux platforms. He studied graphic design at Pikes Peak Community College. This article has been viewed 1,515,782 times.
      How helpful is this?
      Co-authors: 16
      Updated: March 22, 2024
      Views: 1,515,782
      Categories: Linux
      Article SummaryX

      To become root in Linux by gaining access in the terminal, type “su -” and press “Enter” to log in as a “super user.” When you’re prompted, enter the root password and the commands that require root access. If you don’t know the root password and only want temporary root access, then use “sudo” instead of “su-” and enter your own password when prompted. In case of an emergency, like having to deal with disk failure or restoring a locked account, log in as root by entering “root” as the user name followed by the password. When logged in as root, avoid running complex programs, which may have a negative effect on your system when it has root access. To learn how to reset the root or admin password, keep reading!

      Did this summary help you?

      Thanks to all authors for creating a page that has been read 1,515,782 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