30

If I created a user account in Ubuntu called root, would it automatically have root permissions? Break the system? Cause a glitch in the matrix? What would happen?

  • 25
    There already is an account called root. – mikewhatever Oct 8 '16 at 19:37
  • @mikewhatever That's part of his point; root is a special user, so would you get a "special" (i.e. buggy) result? – Sapphire_Brick Aug 13 at 15:46
46

Usernames must be unique, so, as mentioned by Owen Hines' answer, you wouldn't be able to create this user. However, the key point here is that superuser powers (all possible permissions) aren't granted by the username root, but by UID.

The user with UID 0 is the superuser.

So, if the user with UID 0 had a different name, and you created a user called root, they would not have any special status.

I refer you to the tag wiki!

| improve this answer | |
  • Could you rename the existing account root and then create a regular user root? – emory Oct 9 '16 at 18:00
  • As a side note, it appears to be possible (though I haven't tried) to change the uid 0 username to something else, so the superuser is not called root. Not a great idea, but possible. So one could, for instance, make a superuser account called god with uid 0, and a normal user called root with a uid of 1000 or some other number. – Ian D. Scott Oct 10 '16 at 5:32
15

It wouldn't let you because there would already be a root user.

But, as Florian Diesch said in the comments:

Some tools will complain but you can always edit /etc/passwd and etc/shadow manually to create a second user named root.

| improve this answer | |
  • 2
    And if you do this, what happens upon chown root file? – fkraiem Oct 8 '16 at 20:59
  • 1
    @fkraiem, hmm.. good question, I don't know the answer to that. – TheOdd Oct 8 '16 at 21:27
  • 3
    What used to happen is the first one in the file wins. I don't know now. – Joshua Oct 9 '16 at 4:45
5

First the how, as others have stated, you change the user with UID 0 to something else. Then you can create a normal user with the name of root and a UID higher then 1000. It will work "fine". All permissions and core system functions use UID and not user name. In fact this is a good first step in hardening a Linux system. (much better to disable root, but before sudo we used to do this).

Now as to what will happen.

Most of the time nothing. All system calls that have to do with authorization or authentication use UID (that I am aware of). And it has been that way for some time. Your system will keep on running as usual. System tools will reflect the new user name, but continue to work normally. In other words "root" in convention and not set in stone.

That said, I am sure there are some tools and programs that are poorly written. Programs that check the $USER environment variable may act incorrectly. Usually these are scripts and small projects, but you could spend some time tracking down that one bad commit, 6 years ago in fdisk that keeps giving you a headache.

This is something that I used to do all the time. It was an easy step, and falls under the rule of "non-predictable user names". There are MUCH better ways of achieving the same goals today though.

| improve this answer | |
  • you mean UID I think – Zanna Oct 11 '16 at 17:49
1

As others have explained, it's the UID = 0 gives the user "superpowers", not the user name being "root". So if you somehow managed to create another user called "root" (after renaming/deleting the original one) - the user's super-status would depend on the UID you gave it.

Which also leads to another interesting idea: it's totally possible to have multiple users with the same UID (which makes them essentially the same user from the point of filesystem permissions but allow to have different, say, shell and home directory). In fact, some UNIX-like systems have another superuser account called toor (root backwards) which allows to have two super-user accounts with different settings.

| improve this answer | |
1

How to create 2nd 'root':

Yes, in theory, there must be no two users with same username or same IDs. And standard utilities are foolproof and will not make such users for you. But you always can edit /etc/passwd manually.

For example, I did:

$ sudo adduser root2 # created ordinary user
$ sudo vim /etc/passwd # edit last line, change 'root2' to 'root'. 
$ sudo -u '#1002' id # 1002 is UID of new user, it's in last line of /etc/passwd
uid=1002(root) gid=1002(root2) группы=1002(root2)

As you see, we are root now! Yes, thats not real root (not uid=0), but it's same four letters. Impressive and useless.

How to create better 2nd 'root':

Also, you can do other modification. Leave username as-is, (yourname or root2) but change uid.

$ tail -n 1 /etc/passwd
root2:x:0:0:,,,:/home/root2:/bin/bash

(see, UID and GID fields are zeroes) Now you have usual (non-root) user, with almost non-suspicious username (or make username 'johndoe' for better effect), but in fact, this user has superpowers!

$ fdisk /dev/sda
fdisk: unable to open /dev/sda: Permission denied
$ sudo -u root2 fdisk /dev/sda

Command (m for help):

As you see, ordinary user cannot use fdisk on /dev/sda, but root2 can do anything!

This simple trick sometimes used after system is hacked to provide backdoor. Even if real root will change his keys/passwords, hacker still will have full control over system via other user with uid=0.

How matrix works

Actually, neither username 'root', nor uid=0 isn't magical by itself. This is just matter of convention. And it's not even always true. (see this question: Does the root account always have UID/GID 0? ) Kernel code is magical. Actually, userspace code itself - cannot do anything which root can do. Even if runs as root! Root power are in kernel. e.g. if you do "cat /etc/shadow" (only root usually can do this), /bin/cat program calls libc open() function which is still userspace code, and this open() function performs system call to kernel. Then kernel itself decides what do to. For example, kernel may allow some operation if effective user has id==0.

In theory, if you will change some code in kernel and handle 'www-data' user differently - some operations may be allowed only for 'www-data' user (and not allowed even to root).

| improve this answer | |
0

Most 'user-friendly' tools will check against this and won't let you create an account with a username that is already taken.

If you bypass this, and manually add a second root account to your /etc/passwd and /etc/shadow, then which one will be used, i guess would depend if you put it before or after the original one. Like all user accounts on a unix system, it will also have superuser access only if its UID is zero, regardless of the name.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.