Score:-2

How to give root permission to another user without sudo

in flag

Hi want to create a new user in Ubuntu that is same as root who can login using SSH keys, the only difference is the username. (No use of sudo)

I know the risks but it's in my private Network with strict authentication. Thanks ☺️

ru flag
You either give them SSH access to the root account directly (NOT RECOMMENDED!) or you give them sudo access. There is no way to directly 'replicate' the root user and its permissions to a non-root user
terdon avatar
cn flag
@ThomasWard what if you create a new user with UID 0?
terdon avatar
cn flag
Can you explain why you don't just use the `root` user? Why do you need a second root account?
ru flag
@terdon it can cause some odd issues. And can be problematic in the long term for tracking users by uid.
terdon avatar
cn flag
@ThomasWard oh, it's a bad idea for all sorts of reasons, no argument there. I just meant that it is possible (sorta): you can both change the name of the root user and you can create a second one with the same UID. You should not, but you can.
Score:4
cn flag

You can actually do this, although I can't imagine any reason why you would want to. You can create a new user with the same user ID (UID) as root. Note that this isn't actually a "new" user, it is just a different user name for the same user. However, you will be able to log in using this name instead of root.

First, create a new user and set their UID to 0, the UID of the root account:

useradd -d /fool -g root -m -N -o -u 0 -s /bin/bash fool 

The options used are:

  • -d /fool : set this user's $HOME to /fool.
  • -g root : set this user's default group to root.
  • -m: create the user's home directory if it does not exist.
  • -N: do not create a group with the same name as the user, just add the user to the group specified by -g.
  • -o: allow the creation of a user with the same UID as another, existing user.
  • -u 0: set this user's UID to 0 (same as root).
  • -s /bin/bash: set the user's default login shell to bash.
  • fool: the user name will be fool.

After running this command, you will be able to log in as fool:

terdon@ub20:~$ sudo -iu fool
root@ub20:~# whoami
root
root@ub20:~# cd
root@ub20:~# pwd
/fool

As you can see, I have logged in as fool, but whoami (which is based on the UID) sees me as root, while cd will take me to /fool. I have all the rights of the root user, because I am the root user, but my user name and home directories are different. You can now proceed to allow root access over ssh (at your own peril) and log in as fool instead of root. This is all cosmetic, you're still really logging in as root, but that's what you seem to want.

Score:2
cn flag

From a safety perspective, what you want to do obviously is not done and highly recommended against.

Still, it is possible in linux to have different user names representing the same user. So if you want to set up a user name that can act fully as root, you can in principle make a different login name for the root user. One of the reasons why it is extremely imprudent to log in as root by default is that human error easily can cause breakage of the entire system.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.