How to Enable and Disable Root Login in Ubuntu

By default Ubuntu does not set up a root password during installation and therefore you don’t get the facility to log in as root. However, this does not mean that the root account doesn’t exist in Ubuntu or that it can’t be completely accessed. Instead you are given the ability to execute tasks with superuser privileges using sudo command.

Actually, the developers of Ubuntu decided to disable the administrative root account by default. The root account has been given a password which matches no possible encrypted value, thus it may not log in directly by itself.

Attention: Enabling root account is not at all required as most activities in Ubuntu do not actually call for you to use the root account.

Although users are strongly recommended to only use the sudo command to gain root privileges, for one reason or another, you can act as root in a terminal, or enable or disable root account login in the Ubuntu using following ways.

1. How to Enable Root Account in Ubuntu?

To Access/Enable the root user account run the following command and enter the password you set initially for your user (sudo user).

$ sudo -i 
Enable Root Access in Ubuntu
Enable Root Access in Ubuntu

2. How to Change Root Password in Ubuntu?

You can change root password with ‘sudo passwd root‘ command as shown below.

$ sudo passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Change Root Password in Ubuntu
Change Root Password in Ubuntu

3. How to Disable Root Access in Ubuntu?

If you wish to disable root account login, run the command below to set the password to expire.

$ sudo passwd -l root
Disable Root Access in Ubuntu
Disable Root Access in Ubuntu

You may refer Ubuntu documentation for further information.

That’s it. In this article, we explained how to enable and disable root login in Ubuntu Linux. Use the comment form below to ask any questions or make any important additions.

If this article helped, with someone on your team.

TecMint Weekly Newsletter
Get the Learn Linux 7 Days Crash Course free when you join 34,000+ Linux professionals reading every Thursday.
Check your email for a magic link to get started.
Something went wrong. Please try again.
TecMint has been free for 14 years. Help keep it that way.
Google AI Overviews and tools like ChatGPT have cut into search traffic for independent tech sites like TecMint. Running this site costs over $2,000 every month for hosting, infrastructure, and paying authors to keep the content accurate and tested.

If this article helped you solve a problem, consider buying a coffee. It helps keep TecMint free, supports the authors, and keeps the project going.
☕ Buy Me a Coffee
Ravi Saive
I'm Ravi Saive, an award-winning entrepreneur and founder of several successful 5-figure online businesses, including TecMint.com, GeeksMint.com, UbuntuMint.com, and the premium learning hub Pro.Tecmint.com.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

10 Comments

Leave a Reply
  1. I recommend you DO NOT expire the root password! This is not the best way to do it, since normally when you do `useradd sudo` and they then log in and type `su` to go to superuser, it’s going to ask for a password. Guess what password that will be? :) Instead, go into /etc/ssh/sshd_conf and change the value to `PermitRootLogin no`.

    If you want to only use key login, generate a key for your intended super user and then in that same file also set `PasswordAuthentication no` but be careful, obviously make sure your intended super user can escalate to root first.

    Reply
  2. Help I already had an login but just wanted to remove root access but now i rebooted and can’t login i just used the basic login that i got from the start username root password too now when i login it says incorrect password please help

    Reply
  3. Hi Ravi,

    The above tip worked, but i want to activate root account in Ubuntu to login through login window. I am using Ubuntu 14.04.

    Please guide me on this..

    Reply
    • @Arun,

      To login Ubuntu directly as root user, follow below instructions.

      Go to System -> Administration -> Login window -> Security tab, click on the check box “Allow local system administrator” and reboot the system and login directly using root user.

      Reply
  4. `sudo passwd -d root` only removes the password, `sudo passwd -dl root` also locks the account. Key-based SSH access might however still be possible. To completely disable the account use `sudo usermod –expire-date 1 root`

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.

Free Course
Get a free Linux course before you go.
Subscribe to TecMint Weekly and get the Learn Linux 7 Days Crash Course free. Read by 34,000+ Linux professionals every Thursday.
Something went wrong. Please try again.
Check your email for a magic link to get started.