162

I would like to enable the root account on my Ubuntu installation.

I realize the security implications of this.

3
  • See also Why is there no option to log in as root?
    – Shauna
    Feb 28, 2013 at 14:04
  • Daniel M's answer here askubuntu.com/a/1192535/919134 is the only solution that works circa 2023 with my Ubuntu 20.04 Linux
    – Joseph
    Sep 9, 2023 at 9:42
  • When installing most versions of Linux, there is an option to "Lock root account" during the GUI installation process when you configure the root password. The answer to this question varies depending on that checkbox. Feb 18 at 6:48

5 Answers 5

207
+100

Warning

While it's possible to do, it is not recommended.

Enabling

To actually enable root logins first you have to set a password for the root account and then unlock the locked root account. If you don't set a password for the root account the passwd command will return

passwd: unlocking the password would result in a passwordless account.  

So, first execute in a terminal

sudo passwd root

you will be prompted for a new Unix password. Write it twice (second for confirmation).

Then execute

sudo passwd -u root 

to unlock the account. This should return

passwd: password expiry information changed

Reverting

If you want to disable root account in Ubuntu you need to lock the root account by using the following command sudo passwd -l root

Alternatives to root login

If you want to work on a root console you can also use sudo -i.

Only do this if you know what you are doing. More information on why to stay with sudo here

Graphical version needs setting up 1st:

pkexec gnome-terminal will open a terminal with a root prompt.

passwd root will allow you to create a password for root.

Note: Running users-admin with elevated privileges no longer works because of a bug that is marked as "Won't Fix" for security reasons. See https://bugs.launchpad.net/ubuntu/+source/gnome-system-tools/+bug/685215 for an explanation.

pkexec users-admin will open the users screen:im1

Documentation

7
  • 1
    sudo apt-get install gnome-system-tools
    – WitchCraft
    Apr 20, 2016 at 22:00
  • 3
    The link only explains why it's bad to login as root and doesn't give any reason why it's bad to have a root account. As it is on any system with recovery mode, the root account still exists and so if not "enabled" root shell needs no password.
    – mchid
    Aug 2, 2016 at 18:27
  • 1
    I performed the above steps, but there is still no possibilitie to login as root at the start page. Only my user name and guest.
    – Black
    Mar 7, 2017 at 8:08
  • I have an Ubuntu VM and after following this procedure I can log in as 'root' from the console, but I cannot ssh in as 'root'. May 14, 2019 at 19:04
  • 1
    Still can't login as root.
    – Danijel
    Dec 14, 2021 at 9:18
20

You can enable the root account by setting the password as

sudo passwd root

while it is not recommended at all. From help Ubuntu

Enabling the Root account is rarely necessary. Almost everything you need to do as administrator of an Ubuntu system can be done via sudo or gksudo. If you really need a persistent Root login, the best alternative is to simulate a Root login shell using the following command...

And

Use at your own risk!

Logging in to X as root may cause very serious trouble. If you believe you need a root account to perform a certain action, please consult the official support channels first, to make sure there is not a better alternative.

Once enable you can disable the root account as

sudo passwd -l root

Here are the links to enable root login for Ubuntu 12.04 & Ubuntu 12.10

1
14

In Linux there is a special account called root. By default it is locked in Ubuntu but you can enable the root account.

This is normally not a good idea however and you should consider very carefully before enabling the root login.

There are several good reasons not to login as root but use sudo instead including

  • Users don't have to remember an extra password (i.e. the root password), which they are likely to forget (or write down so anyone can crack into their account easily).

  • It avoids the "I can do anything" interactive login by default (e.g. the tendency by users to login as an "Administrator" user in Microsoft Windows systems), you will be prompted for a password before major changes can happen, which should make you think about the consequences of what you are doing.

  • sudo adds a log entry of the command(s) run (in /var/log/auth.log). If you mess up, you can always go back and see what commands were run. It is also nice for auditing.

  • Every cracker trying to brute-force their way into your box will know it has an account named Root and will try that first. What they don't know is what the usernames of your other users are. Since the Root account password is locked, this attack becomes essentially meaningless, since there is no password to crack or guess in the first place.

  • Allows easy transfer for admin rights, in a short term or long term period, by adding and removing users from groups, while not compromising the Root account. sudo can be setup with a much more fine-grained security policy.

This is discussed in more detail in the RootSudo Comunity Documentation

If you have a number of commands which would normally require sudo you can type sudo -i before the first command then exit after the last to avoid repeatedly typing sudo. To run a GUI application with root priviledges press ALT+F2 and enter gksu or gksudo followed by the name of your program (unless you are using the KDE desktop in which case the command is kdesu.

For example gksu nautilus runs the file manager with root privileges.

As you can see it is almost never necessary to enable the root login.

That said to enable the root login all that is required is to set a root password

sudo passwd root

and set a password. You will then be able to login as root but for all the reasons I have given above and more I would not recommend you do it.

3
  • "There are several good reasons not to login but use root instead including" Shouldn't that be "...but use sudo instead"?
    – Shauna
    Feb 28, 2013 at 14:02
  • 1
    @Shauna thanks for pointing that out -- post edited. Feb 28, 2013 at 14:22
  • Daniel M's answer here askubuntu.com/a/1192535/919134 is the only solution that works circa 2023 with my Ubuntu 20.04 Linux
    – Joseph
    Sep 9, 2023 at 9:41
7

There's no need for an enabled root account. You can simply use sudo -i to have a superuser prompt as if you'd logged in as root. That avoids the security risk of allowing direct logins as root.

3
  • no it does not i can still format the / partition .
    – Lincity
    May 22, 2011 at 14:22
  • Of course you can still format the / partition with sudo. The most common use of sudo, especially in Ubuntu, is to temporarily grant superuser permissions, which allow you to change almost any aspect of the system -- and sometimes formatting the / partition really is the order of the day. My understanding was that the primary reason to disallow direct logins as root -- as opposed to logging in as a regular user and using su to relogin as root -- was that it requires a login by a regular user first, which is logged. Secondarily, it discourages habitual logins as root, which is a sloppy habit.
    – bgvaughan
    May 22, 2011 at 15:25
  • Daniel M's answer here askubuntu.com/a/1192535/919134 is the only solution that works circa 2023 with my Ubuntu 20.04 Linux
    – Joseph
    Sep 9, 2023 at 9:41
4

Simple answer: Yes, you can do it.

Currently there are two things preventing root from logging in on default Ubuntu.

  1. The root user doesn't have a password set

  2. They have "!" (an exclamation mark) in their /etc/shadow entry

The following command fixes both issues in one go:

sudo passwd -u root

The -u part is needed because of the "!" on their account.

3
  • 3
    Have you tried it ? Because I did and the result was passwd: unlocking the password would result in a passwordless account. You should set a password with usermod -p to unlock the password of this account. So I assume, first you have to SET the root password before you unlock it.
    – NickTux
    Dec 30, 2013 at 22:48
  • My interpretation of this command is that it unlocks the password AND sets it, prompting you for the new password interactively in the console. If you are calling this from a non-interactive context like a script called by something else you may have to modify this to include the password in the command line - which passwd can do. Mar 13, 2019 at 1:49
  • Daniel M's answer here askubuntu.com/a/1192535/919134 is the only solution that works circa 2023 with my Ubuntu 20.04 Linux
    – Joseph
    Sep 9, 2023 at 9:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .