Friday, 19 March 2021

How To Create User with Gecos/Comment and Add in a Group in CentOS 7



A new user account is created with a group. The group name is same as account name and the user is the only member of this group. The -g [Primary Group] and -G [Secondary Group] options allow to add the user in primary and secondary group and the -c (--comment) option allows to add a short description/User Full Name/GECOS for the new user.
This article describes, How To Create User with Gecos and Add in a Group in CentOS 7.
 
Step 1: User Creation: Run the following command to create the user with Gecos and adding into secondary group:
 
[root@linuxcnf ~]# useradd -c "User1 Name" -G somegroup user1
[root@linuxcnf ~]#
 
Step 2. Validate the User: Run the following command to validate the user creation:
 
[root@linuxcnf ~]# grep -i user1 /etc/passwd
user1:x:1000:1001:User1 Name:/home/user1:/bin/bash
[root@linuxcnf ~]#
 
Step 3. Validate the Group: Run the following command to validate the group of the user:
 
[root@linuxcnf ~]#grep -i user1 /etc/group
somegroup:x:1000:user1
user1:x:1001:
[root@linuxcnf ~]#
 
Done! User created with GECOS and added into secondary group.

No comments:

Post a Comment