CentOS 7 is a popular Linux distribution used by many organizations for their servers and workstations. One of the important aspects of system administration is managing users, groups, and permissions. In this blog, we will explore how to create and manage users, groups, and permissions in CentOS 7.
Creating Users in CentOS 7
Creating a user in CentOS 7 is a simple process.
To create a user, you need to have root privileges. Once you have the root privileges, follow the steps below to create a new user:
Step 1: Open the terminal and log in as the root user.
sudo su
Step 2: Use the adduser command to create a new user. Replace ‘username’ with the desired username for the new user.
adduser username
Step 3: Set a password for the user by running the following command. Replace ‘username’ with the username of the new user.
passwd username
Managing Users in CentOS 7
You can manage users in CentOS 7 using the usermod command. Some of the common tasks that you can perform using the usermod command are:
- Change the user’s home directory:
usermod -d /new/home/directory username
- Change the user’s login name:
usermod -l newusername oldusername
- Add the user to a group:
usermod -aG groupname username
- Lock the user’s account:
usermod -L username
- Unlock the user’s account:
usermod -U username
Creating Groups in CentOS 7
Creating a group in CentOS 7 is similar to creating a user. Follow the steps below to create a new group:
Step 1: Open the terminal and log in as the root user.
sudo su
Step 2: Use the groupadd command to create a new group. Replace ‘groupname’ with the desired group name.
groupadd groupname
Managing Groups in CentOS 7
You can manage groups in CentOS 7 using the groupmod command. Some of the common tasks that you can perform using the groupmod command are:
- Change the group’s name:
groupmod -n newgroupname oldgroupname
- Add a user to the group:
gpasswd -a username groupname
- Remove a user from the group:
gpasswd -d username groupname
- Delete a group:
groupdel groupname
Setting Permissions in CentOS 7
Permissions are used to control access to files and directories in CentOS 7. The chmod command is used to set permissions on files and directories. The chmod command uses a three-digit code to set permissions.
The three-digit code consists of the following:
- The first digit specifies the file type and sets the special permissions.
- The second digit specifies the permissions for the owner of the file.
- The third digit specifies the permissions for the group owner of the file.
- The fourth digit specifies the permissions for everyone else.
The digits can have values from 0 to 7. The value of each digit determines the permissions that are set. The values and their corresponding permissions are:
0: No permissions 1: Execute 2: Write 3: Write and execute 4: Read 5: Read and execute 6: Read and write 7: Read, write, and execute
For example, to set the permissions of a file to read and write for the owner, read-only for the group owner, and read-only for everyone