Download Article
Run commands with root access or enable root logins with ease
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.
Steps
-
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] X Research source 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.
-
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 -
Use sudo -H 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] X Research source However, this should work for most programs if you absolutely must.
- The gksudo command is now deprecated in Ubuntu.
-
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).
Advertisement
-
Press Ctrl + Alt + T to open a terminal window. 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.
- Enabling the root user can put your system at risk and is not recommended by Ubuntu. [3] X Research source
-
Type sudo passwd root and press ↵ Enter . You will be prompted to set a new password for the root user. Don’t lose this password.
-
Enter a password, then press ↵ Enter .
-
Retype the password when prompted, then press ↵ Enter . The root user should now have a password.
-
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 -l root . [4] X Research source
Advertisement
-
Press Ctrl + Alt + T to open a terminal window. 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.
- If you haven't enabled the root user yet, use this method to do so.
-
Use su - to become root. 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.
-
Open /etc/gdm3/custom.conf in a text editor. Use sudo to run the command. For example, if you use vim as your text editor, use sudo vim /etc/gdm3/custom.conf .
-
Add a new entry. 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.
-
Edit /etc/pam.d/gdm-password for editing. Again, use sudo, e.g., sudo vim /etc/pam.d/gdm-password if you prefer vim.
-
Comment out the line "auth required pam_succeed_If." To do this, enter a hash symbol (#) before the line: # auth required pam_succeed_If .
- 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.
Advertisement
-
Open /etc/ssh/sshd_config in any text editor. 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 .
- If you haven't enabled the root user yet, use this method to do so.
-
Uncomment the PermitRootLogin line. The line you're looking for is #PermitRootLogin prohibit-password . To uncomment, just remove the hashmark at the beginning.
-
Replace prohibit-password with yes . The line should now look like PermitRootLogin yes .
-
Restart sshd. 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.
Advertisement
Community Q&A
Search
-
QuestionI 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 Answergksudo won't work in a Wayland session; switch to an Xorg session and try.
-
QuestionHow to administer password created by command?JisjoCommunity AnswerYou 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.
-
Questioni did the steps for enabling and setting password for root but after typing: " sudo - " it still says su: Authentication failure. What should I do?JisjoCommunity AnswerThe 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.
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement
Video
Tips
- Avoid logging in as root as much as possible. You can run almost any superuser-required command with sudo .Thanks
- 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).Thanks
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
References
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,214,803 times.
Advertisement