Download ArticleDownload Article

To run administrative tasks in Linux, you must have root (also known as superuser) access. Having a separate root account is common in most Linux distributions, but Ubuntu disables root by default. This prevents users from making mistakes and keeps the system safe from intruders. To run commands that require root access, use sudo.

Root for Ubuntu

  1. Press Ctrl + Alt + T to open a terminal window.
  2. Type “sudo” before the rest of your command to run it as root.
  3. If the program requires a GUI, type “gksudo” instead of “sudo.”
Method 1
Method 1 of 2:

Running Root Commands with Sudo

Download Article
  1. How.com.vn English: Step 1 Press Ctrl+Alt+T to...
    Press Ctrl+Alt+T to open a terminal window. Because Ubuntu locks the root account by default, you cannot use su to become root as you would in other Linux distributions.[1] Instead, start your commands with sudo.
  2. How.com.vn English: Step 2 Type sudo before the rest of your command.
    “Sudo” stands for “substitute user do.” When you add sudo to the beginning of a command, the command will run as root.
    • For example: sudo /etc/init.d/networking stop stops the network service, and sudo adduser adds a new user to the system. Both of these tasks require root access.
    • You will be prompted to enter your password before sudo runs the command. Linux stores your password for 15 minutes so you won’t have to keep typing it.
    Advertisement
  3. How.com.vn English: Step 3 Type gksudo before running a command that opens a program with a Graphical User Interface (GUI).
    For security reasons, Ubuntu does not recommend using “sudo” to open programs with GUIs.[2] Instead, type gksudo before the command that launches the program.
    • For example: type gksudo gedit /etc/fstab to open the "fstab" file in GEdit, an editing program with a GUI.
    • If you’re using the KDE Window Manager, use kdesudo instead of gksudo.
  4. How.com.vn English: Step 4 Simulate a root environment.
    If you are an advanced user who needs access to an actual root shell to run specific scripts, simulate a root shell with sudo –i. This command will give you superuser access with root’s environment variables.
    • Enter the command sudo passwd root. This will create a password for root, essentially “enabling” the account. Don't forget this password.
    • Type sudo -i. Enter the root password when prompted.
    • The prompt will change from $ to #, indicating you have root access.
  5. How.com.vn English: Step 5 Give sudo access to another user.
    If you are setting up an account for someone who does not currently have root access, you will need to add their username to the sudo group. To do this, type usermod -aG sudo username (but replace “username” with the correct username).[3]
  6. Advertisement
Method 2
Method 2 of 2:

Enabling the Root User

Download Article
  1. How.com.vn English: Step 1 Press Ctrl+Alt+T to open a terminal window.
    For security purposes (and to avoid damage), the root user account is locked by default. To safely run commands as root, you should use sudo or gksudo instead. If you absolutely must have a separate root user (if it’s required by a program used by your business, or this workstation will only be used by a single user), you can enable the root user with some simple commands.
    • Enabling the root user can put your system at risk and is not recommended by Ubuntu.[4]
  2. How.com.vn English: Step 2 Type sudo passwd root and press ↵ Enter.
    You will be prompted to set a new password for the root user.[5] Don’t lose this password.
  3. How.com.vn English: Step 3 Enter a password, then press ↵ Enter.
  4. How.com.vn English: Step 4 Retype the password when prompted, then press ↵ Enter.
    The root user should now have a password.
  5. How.com.vn English: Step 5 Type su - and press ↵ Enter.
    Enter the root password when prompted to arrive at the root prompt.
    • To disable the root account, type sudo passwd -dl root.[6]
  6. Advertisement

Community Q&A

Search
Add New Question
  • Question
    I read the article and tried gksudo on Ubuntu, but it doesn't work. I learned that it is abolished by most flavors of Linux. What do I do?
    How.com.vn English: Thomas J. Jordan Sr.
    Thomas J. Jordan Sr.
    Community Answer
    gksudo won't work in a Wayland session; switch to an Xorg session and try.
  • Question
    How to administer password created by command?
    How.com.vn English: Jisjo
    Jisjo
    Community Answer
    You can create a root password by command line. In Linux root has Administrator like the Windows Operating system. Use this below command to set root password: $ sudo passwd root.
  • Question
    i did the steps for enabling and setting password for root but after typing: " sudo - " it still says su: Authentication failure. What should I do?
    How.com.vn English: Jisjo
    Jisjo
    Community Answer
    The error "su: Authentication failure" shows for an incorrect password login. Give the correct password to fix this. Also, there is no command like "sudo - ", refer to the article for correct usage.
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

      • You should avoid logging in as root as much as possible. You can run almost any superuser-required command withsudo or gksudo.
      • You can also use sudo –i to access the shell of another user on the system. To become user “jane, “ type sudo –I jane and then enter YOUR password when prompted (not Jane’s).
      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: Nicole Levine, MFA
      Written by:
      How.com.vn Technology Writer
      This article was co-authored by How.com.vn staff writer, Nicole Levine, MFA. Nicole Levine is a Technology Writer and Editor for How.com.vn. She has more than 20 years of experience creating technical documentation and leading support teams at major web hosting and software companies. Nicole also holds an MFA in Creative Writing from Portland State University and teaches composition, fiction-writing, and zine-making at various institutions. This article has been viewed 1,188,773 times.
      How helpful is this?
      Co-authors: 18
      Updated: April 16, 2024
      Views: 1,188,773
      Categories: Ubuntu
      Article SummaryX

      To run a command as root, type “sudo” before the command. Use “gksudo” if the command opens a program with a Graphical User Interface (GUI).

      Did this summary help you?

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