Creating and managing users and groups is an essential aspect of system administration in CentOS. Here's how you can create and manage users and groups in CentOS:
1. Creating Users:
-
To create a new user, you can use the
useraddcommand followed by the username. For example:sudo useradd usernameReplace
usernamewith the desired username. -
You can also specify additional options when creating a user, such as the user's home directory and login shell. For example:
sudo useradd -m -s /bin/bash usernameThis command creates a user with a home directory and sets
/bin/bashas the default login shell.
2. Setting User Password:
- After creating a user, you need to set a password for the user using the
passwdcommand. For example:
You will be prompted to enter and confirm the password for the user.sudo passwd username
3. Creating Groups:
- To create a new group, you can use the
groupaddcommand followed by the group name. For example:
Replacesudo groupadd groupnamegroupnamewith the desired group name.
4. Adding Users to Groups:
- To add a user to an existing group, you can use the
usermodcommand with the-aGoption. For example:
Replacesudo usermod -aG groupname usernamegroupnamewith the name of the group andusernamewith the name of the user you want to add to the group.
5. Listing Users and Groups:
- To list all users on the system, you can use the
getentcommand with thepasswddatabase. For example:getent passwd - To list all groups on the system, you can use the
getentcommand with thegroupdatabase. For example:getent group
6. Modifying Users and Groups:
-
You can modify user and group properties using commands like
usermodandgroupmod. For example:sudo usermod -s /bin/bash usernameThis command changes the login shell for the specified user.
-
Similarly, you can use
groupmodto modify group properties. For example:sudo groupmod -n newgroupname oldgroupnameThis command renames an existing group.
7. Removing Users and Groups:
- To remove a user, you can use the
userdelcommand. For example:sudo userdel username - To remove a group, you can use the
groupdelcommand. For example:sudo groupdel groupname
8. Additional User and Group Management Tools:
- CentOS also provides graphical tools like
usermanagerandgroupmanagerfor managing users and groups in a desktop environment.

Comments