PDF download Download Article
Run commands with root access or enable root logins with ease
PDF download Download Article

To run administrative tasks in Linux, you must have root (also known as superuser) access. While having a separate root account is common in most Linux distributions, Ubuntu disables root logins by default. To run commands with root permissions, it's best to use sudo . However, if you must log in as root or get a root shell, it's easy to enable the root account. This guide will teach you multiple ways to become root in Ubuntu Linux.

Becoming Root in Ubuntu: Quick Options

  • To run a command as root, type sudo before the rest of the command (e.g., sudo vim /etc/httpd.conf ).
  • To enable the root user, use sudo passwd rt to create a root account and passwd.
  • To access a root shell after enabling root, use su - .
Method 1
Method 1 of 4:

Running Root Commands with Sudo

PDF download Download Article
  1. Press Ctrl + Alt + T to open a terminal window . [1] Because Ubuntu locks the root account by default, you cannot use su to become root as you would in other Linux distributions. [2] Instead, start your commands with sudo .
    • If you want to enable the root user in Ubuntu so you can log in as root, see Enabling the Root User . We don't recommend doing this for security reasons, but it is possible.
  2. “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. For security reasons, Ubuntu does not recommend using “sudo” to open programs with GUIs. [3] However, this should work for most programs if you absolutely must.
    • The gksudo command is now deprecated in Ubuntu.
  4. 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).
  5. Advertisement
Method 2
Method 2 of 4:

PDF download Download Article
  1. For security purposes (and to avoid damage), the root user account is locked by default in Ubuntu. If you must have a root login (if a program your business uses requires it, or this workstation will only be used by a single user), you can enable the root user with some simple commands. [4]
    • Enabling the root user can put your system at risk and is not recommended by Ubuntu. [5]
  2. You will be prompted to set a new password for the root user. Don’t lose this password.
  3. The root user should now have a password.
  4. Enter the root password when prompted to arrive at the root prompt.
    • To disable the root account, type sudo passwd -l root . [6]
  5. Advertisement
Method 3
Method 3 of 4:

PDF download Download Article
  1. If you've enabled the root user, you won't be able to log in to the Ubuntu GUI as root unless you enable root GUI login. We really don't recommend doing this, but it is possible. [7]
    • If you haven't enabled the root user yet, use this method to do so.
  2. As long as you've enabled the root user , this will give you a root shell. When prompted for a password, enter the root password you've set for Ubuntu.
  3. Use sudo to run the command. For example, if you use vim as your text editor, use sudo vim /etc/gdm3/custom.conf .
  4. Here's what you'll need to add:
    • Under "TimedLogInDelay = 10", open a new line.
    • Type AllowRoot=True .
    • Save your changes and close the file.
  5. Again, use sudo, e.g., sudo vim /etc/pam.d/gdm-password if you prefer vim.
  6. To do this, enter a hash symbol (#) before the line: # auth required pam_succeed_If . [8]
    • When you're finished, save and close the file.
    • To log in as root on the login screen, select Not Listed from the login menu, then type root as the user. Enter the root password to log in.
    • To disable root login at the GUI login screen, simply delete the line you added to /etc/gdm3/custom.conf and uncomment the line you commented in etc/pam.d/gdm-password.
  7. Advertisement
Method 4
Method 4 of 4:

PDF download Download Article
  1. You'll need root access to edit this file, so open it using sudo. For example, if you want to open it in vim, use sudo vim /etc/ssh/sshd_config . [9]
    • If you haven't enabled the root user yet, use this method to do so.
  2. The line you're looking for is #PermitRootLogin prohibit-password . To uncomment, just remove the hashmark at the beginning.
  3. The line should now look like PermitRootLogin yes . [10]
  4. To do this, use sudo systemctl restart ssh . This allows the root user to log in via SSH.
    • To reverse this, just comment out the line again.
  5. 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?
    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?
    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?
    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
      Advertisement

      Video

      Tips

      • Avoid logging in as root as much as possible. You can run almost any superuser-required command with sudo .
      • You can use su to access the shell of another user on the system. To become user “jane," type su - jane and then enter YOUR password when prompted (not Jane’s).
      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Name
      Please provide your name and last initial
      Thanks for submitting a tip for review!
      Advertisement

      About This Article

      Article Summary X

      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,217,781 times.

      Is this article up to date?

      Advertisement