Add User to root Group on CentOS VPS

1. Add a new user. In this example, I used ‘myroot’ and then set the password.

[root@CentOS57 ~]# useradd myroot
[root@CentOS57 ~]# 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.

[root@CentOS57 ~]# groups
root bin daemon sys adm disk wheel

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

[root@CentOS57 ~]# usermod -G root myroot

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

[root@CentOS57 ~]# su - myroot
[myroot@CentOS57 ~]$ groups
myroot root

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

[root@CentOS57 ~]# grep myroot /etc/group

6. Edit /etc/passwd file,find the following line,change the user ID to 0 :


After modification:


save,get root privilege after login as myroot。

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


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s