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

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.

READ  How to Setup Squid Proxy in Ubuntu Server 14.04

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

[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

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

READ  How to Install Lighttpd With PHP5 (PHP-FPM) and MySQL on CentOS 6.5

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. Check the file permission for /etc/passwd

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

  1. Moh3nia
    September 17, 2012 at 10:11 pm

    thanks sir for this amaznig tut

  2. manjit
    June 9, 2014 at 4:39 pm

    not working…

  3. Paul
    December 12, 2015 at 4:19 pm

    Thank you, It helped me out.
    Bookmarked this page for future reference.

  4. gnome
    April 30, 2016 at 6:50 pm

    worked well on Centos 5.2

Leave a Reply

Your email address will not be published. Required fields are marked *

A world leading hosting company that provides fully-managed innovative and secure solutions, suitable for hosting small to medium-sized websites

Built on the best available technologies combined with Google Cloud for strong redundancy and application availability. Backed by skilled experts to address web security threats, a devops team to create advanced custom security solutions, and 24/7 sysadmins to watch over the platform. This powerful, hands-on approach makes your sites faster, safer, and easier to manage. Starting from only $3.95/mo.


* up to 30 days money back guarantee