How to Add User to root Group on CentOS 5/CentOS 6

Share this Article :

useradd is a low-level utility to create new users to the system. When used without the -D option, useradd command will create a new user account using the command line plus the default values ??of the system. Depending on the command line option, useradd command will update system files and also can create new user’s home directory. In this article, I will explain to you how to create a user then add it to the particular group in CentOS 5 and CentOS 6. Prior to that , this article assumes that the server CentOS 5 or CentOS 6 has been fully installed.

Also Read :   How to Fix “Repository moved permanently to… please relocate” Error In Subversion

1. Add a new user. In this example, the username will be ‘myroot‘.

[[email protected] ~]# useradd myroot
[[email protected] ~]# passwd myroot
Changing password for user myroot.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

2. Check current groups for ‘root‘ user.

[[email protected] ~]# groups
root bin daemon sys adm disk wheel

3. Add ‘myroot‘ into root group as below:
useradd -G {group-name} username

[[email protected] ~]# usermod -G root myroot

Above is example, we are adding a user ‘myroot‘ into group ‘root‘.

4. Switch to ‘myroot‘ user. Then Check current group for ‘myroot‘. root group will be the second group for ‘myroot’.

[[email protected] ~]# su - myroot
[[email protected] ~]$ groups
myroot root

5. Grep the ‘myroot’ user’s group.

[[email protected] ~]# grep myroot /etc/group
root:x:0:root,myroot
myroot:x:502:

6. Check the file permission for /etc/passwd

[[email protected] ~]# ls -al /etc/passwd
-rw-r--r-- 1 root root 1026 Jan 21 05:32 /etc/passwd

Explanation : Only the owner which is ‘root’ user can edit the /etc/passwd file, not in the root’s group.


4 Comments

  1. Moh3nia
  2. manjit

Leave a Reply