How can you turn a root user into a normal user?

When I first set up ubuntu, I did most of my stuff in the root account. However, working exclusively in the root account is a bad idea. How can I turn my root account into a normal account without root privileges without deleting it?

Asked By: joyoforigami


The root user, or the superuser, in Linux is defined by the fact that it has user ID 0. So while it might be theoretically doable to "turn root user into a normal user", it would require some tricky editing of /etc/passwd and /etc/shadow files to change the user ID of that user to some other number while simultaneously creating another user with user ID 0 (as Linux cannot properly function without a superuser). Also, you would need to change ownership of all files that you created as root to the new user ID anyway.

That basically equals to creation of a new user and moving all the files to a new user (with appropriate ownership change), so I would recommend it as a cleaner and "safer" solution.

  1. Create a new user (let’s call it newuser).
  2. Move all files and directories from /root to /home/newuser. Do not forget hidden files/directories as they contain config data, but leave out the files that are by default created in any new user’s directory – typically .bashrc, .bash_logout and .profile – they should stay in /root directory.
  3. Change (recursively) ownership of all files and subdirectories in /home/newuser to newuser (and appropriate group).
  4. Some of your software may still not function properly, if it has absolute paths to previous location (ie. /root) stored anywhere in its config. Grep (recursively, you can use find for this) all files in "dotted" subdirectories to check if any of them contains the path /root – if yes, you should change it to /home/newuser.
Answered By: raj
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.