CentOS /Linux: Create New User and Usergroup Using groupadd and useradd Command

For a linux newbie, how to create a normal user and user group under CentOS Linux operating system or RHEL Linux system? In this post you will see the steps to create user and user group using useradd and group add command.

​CentOS Linux Creating User and User Group

Firstly, if you want to create a user or user group , you must login the system with root privilege and normal user do not have permission to create user or group . so issue the following command to create a user group named as “testg”:

$sudo groupadd testg

Then try to type the below command to create a user also named as testg:

$sudo useradd testg

Outputs:

[devops@osetc~]$ sudo useradd testg

useradd: group testg exists – if you want to add this user to that group, use -g.

For above output, you must be seen that user testg failed to create, as when you create a user using useradd command, it will create a group and its group name same as with user name . so now creating testg user will fail .  how to workaround this problem?  the command output have gave you a refer information, you can try to use “-g” option. so issue the following command:

$ sudo useradd -g testg testg

“testg” user created now…

Next, we need to set password for “testg” user, using “passwd” command, type:

$sudo passwd testg

Outputs:

[devops@osetc~]$ sudo  passwd testg
Changing password for user testg.
New password:
BAD PASSWORD: it is WAY too short
BAD PASSWORD: is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.

Now you can try to login the CentOS system with testg user using “su testg” command.

[devops@osetc~]$ su testg
[testg@c668f1n02 devops]$ id testg
uid=501(testg) gid=2600(testg) groups=2600(testg)

done….

You might also like:

Sidebar



back to top