0

Can I userdel root? If not, then is there a way to remove root user? Also what would be the consequences of doing so?

Tried looking around on google, and asked in a few discords, but couldn't get a satisfactory answer

Sotto Voce
  • 3,664
  • 1
  • 8
  • 21
  • 3
    You do not want to make this, trust me – Romeo Ninov Aug 02 '23 at 16:10
  • 1
    I imagine (and hope) this action is inhibited, but I am not dumb enough to try it. As only root can `useradd`, you can never create any new user (including reinstating root itself). As the user's home directory is removed recursively, and root owns `/`, you would probably erase the complete file system, including all the kernels and boot mechanism. Let us know how it goes, please (you may need to use a different device to access this site). – Paul_Pedant Aug 02 '23 at 16:13
  • @Paul_Pedant the root home directory is often `/root` these days, precisely so that you are less likely to delete major parts of the system accidentally – roaima Aug 02 '23 at 16:42
  • Out of curiosity: **why** would you want to do that? – tink Aug 02 '23 at 19:27
  • This is a big XY question. What do want to accomplish? Do you want to rename `root`? How will you deal with all the files owned by UID 0? What about UID 0 processes? You have skipped far too many steps along your journey towards Linux knowledge. One must figure out "how it works" before one meddles. – waltinator Aug 02 '23 at 23:40

1 Answers1

1

No, don't delete the root user.

In Linux (like Unix), a large number of system processes depend on the root user being present in the server configuration. Although people may not log into the root user often, the system software makes constant use of the account to own files and directories, and to run processes whose internal data structures and on-disk files should not be exposed to the ordinary user accounts that people use.

Certainly create a non-root user account for yourself to use on the system, but don't delete the root user. If you do, many things will break, including your ability to log into the system and gain the privileges needed to repair the deletion.

Sotto Voce
  • 3,664
  • 1
  • 8
  • 21
  • 1
    Technically it's possible; QNAP for example has no `root` user (by name) and instead has chosen to call the UID 0 account `admin`. You'd need to check that all utilities - particularly scripts, where `getuid(2)` isn't a standard thing - tested against uid=0 rather than name=root – roaima Aug 02 '23 at 16:44
  • @roaima if this question were about QNAP the OP would have asked about deleting the admin user. The available evidence indicates the OS involved would "hork" if the root user were deleted. – Sotto Voce Aug 02 '23 at 20:54
  • If it were about the QNAP, indeed. I was simply pointing out that it is possible as it's been done. Don't get me wrong, though, I wouldn't recommend it lightly. Or at all, really. (I had never heard of that word until last week. I wonder where AC first came across it as I wouldn't say it was (British) English; I've seen "barf" or maybe just possibly "honk" with an "n". How about https://english.stackexchange.com/questions/tagged/etymology?) – roaima Aug 02 '23 at 23:22
  • It doesn't matter what it's called or what username it has (or even if it has one), **uid 0 is root**, and that's built in to the kernel. root can have more than one /etc/passwd or NSS entry - with different names & maybe different home dir, gecos field, shell, etc - but they're ALL root (e.g. root with csh and toor with sh or bash is common on *bsd). root always exists - the account name isn't terribly important (although, as @roaima says, any programs that hard-code the name "root" rather than uid 0 may break in various ways if the entry for root is deleted or renamed). – cas Aug 03 '23 at 01:59
  • re: "hork", there was a question about that here just a few days ago: [What is "horkage"?](https://unix.stackexchange.com/questions/752755/what-is-horkage). it's slang for break or mess up. it's not a term i use (i prefer borked or broken/breakage or plain old fucked), but i recognise its meaning when i see it. – cas Aug 03 '23 at 02:08