Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

On all the Linux systems I've managed, the root account has a GID and UID of 0. Is this guaranteed, or is it possible that the system will give root a different ID?

share|improve this question
2  
ID 0 has all the rights. The actual name (or names -multiple-) can differ. E.g. my server has two uid 0 users. One called 'root', one called 'toor'. –  Hennes Aug 1 '13 at 19:20

2 Answers 2

up vote 34 down vote accepted

There are actually two parts to your question.

Does the superuser account always have uid/gid 0/0 on Linux?

Yes. As is pointed out by Rich Homolka in a comment, there's code in the kernel which explicitly checks for uid 0 when needing to check for the root user, which means that root always has at least uid 0.

Is the name of the user account with uid 0 always root?

No. root is just a name, listed in /etc/passwd or some other authentication store. You could just as well call the account admin, and the OS itself won't care, but some applications might not quite like it because they expect there to exist a privileged account named root. Calling the uid 0 account on a *nix root is a very strongly held convention, but it isn't required by the system.

It's also worth noting that, as pointed out by Simon Richter, on BSDs there often exists a second uid 0 account, by convention named toor (which is "root" spelled backwards). For example, FreeBSD uses it to provide a root user with a customized shell setting, leaving the root user with a default shell which is guaranteed to exist on the system's root partition (useful for recovery purposes).

share|improve this answer
    
Absolutely correct. –  Tonny Aug 1 '13 at 19:21
4  
There's code in the kernel to check for root, uid == 0. Yes, it's hard coded and permanent. –  Rich Homolka Aug 1 '13 at 19:25
    
BSD typically has root and toor, both with UID 0. –  Simon Richter Aug 2 '13 at 11:44
    
@SimonRichter In which case there exists a superuser account with the name root, so no issue there as long as the authentication store libraries don't get confused at the two users with the same UID (in which case the BSDs wouldn't do it that way, or the libraries would get fixed). –  Michael Kjörling Aug 2 '13 at 11:46

1) the administrator is always uid == 0. This is coded in the kernel. It would take some coding in the kernel to change this. There's not much point to this, so it's not done. For example, it would be inconsistent for other unixes sharing the same NFS for example.

2) uid 0 does not necessarily map to root. The best example is FreeBSD. It has two uid == 0 accounts, the difference being the shell. root has shell /bin/sh, which is a simple shell, useful for when your disks are bad and you need fsck /usr. toor uses tcsh, which is much more useful in non-emergency situations,since it has things like history, etc.

Another, more personal example; one job I had where they had a root equiv (i.e. uid=0) account over NIS. The password, blank! Because the new sysadmin couldn't remember the root password on the machines. I yelled about this for obvious reasons (NIS passwords by definition can not hide their blankness). I was not happy about this account.

And it really isn't the system that gives uid 0 is root, it's you. You change this my using passwd files, or other naming directories (NIS, ldap) but it's not compiled in. Though you should have at least one uid 0 account in /etc/passwd, since you may not have networking when you really need it.

So root is always uid 0, but uid 0 is not necessarily always root.

share|improve this answer
    
Oof, the pain of choosing only one accepted answer... –  Tanaki Aug 1 '13 at 22:28
1  
@Tanaki Generally, "accept" the answer that helped you the most to answer your question, and upvote all the answers you found useful. There's nothing saying you have to accept the highest-voted or first-written answer. –  Michael Kjörling Aug 2 '13 at 11:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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