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
root:x:0:root,myroot
myroot:x:502:

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

myroot:x:500:500:junguoguo:/home/myroot:/bin/bash

After modification:

myroot:x:0:500:junguoguo:/home/myroot:/bin/bash

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.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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