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
useradd
command followed by the username. For example:sudo useradd username
Replace
username
with 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 username
This command creates a user with a home directory and sets
/bin/bash
as the default login shell.
2. Setting User Password:
- After creating a user, you need to set a password for the user using the
passwd
command. For example:sudo passwd username
3. Creating Groups:
- To create a new group, you can use the
groupadd
command followed by the group name. For example:sudo groupadd groupname
groupname
with the desired group name.
4. Adding Users to Groups:
- To add a user to an existing group, you can use the
usermod
command with the-aG
option. For example:sudo usermod -aG groupname username
groupname
with the name of the group andusername
with 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
getent
command with thepasswd
database. For example:getent passwd
- To list all groups on the system, you can use the
getent
command with thegroup
database. For example:getent group
6. Modifying Users and Groups:
-
You can modify user and group properties using commands like
usermod
andgroupmod
. For example:sudo usermod -s /bin/bash username
This command changes the login shell for the specified user.
-
Similarly, you can use
groupmod
to modify group properties. For example:sudo groupmod -n newgroupname oldgroupname
This command renames an existing group.
7. Removing Users and Groups:
- To remove a user, you can use the
userdel
command. For example:sudo userdel username
- To remove a group, you can use the
groupdel
command. For example:sudo groupdel groupname
8. Additional User and Group Management Tools:
- CentOS also provides graphical tools like
usermanager
andgroupmanager
for managing users and groups in a desktop environment.
Comments