Working with Users and Groups
Introduction to Users and Groups
In Linux, a user is a person or an application that uses the system. Each user has a unique username, and each user belongs to one or more groups. A group is a collection of users that share a set of permissions or access to certain resources.
By default, Linux comes with a set of predefined users and groups. However, you can create new users and groups as needed to control access to the system and its resources.
Creating and Managing Users
To create a new user, you can use the useradd
command followed by the desired username. For example, to create a user named "johndoe", you would enter:
sudo useradd johndoe
Once the user is created, you can set a password for the user using the passwd
command:
sudo passwd johndoe
You can also modify the user's properties using the usermod
command. For example, to add the user "johndoe" to the "sudo" group, you would enter:
sudo usermod -aG sudo johndoe
To delete a user, you can use the userdel
command followed by the username:
sudo userdel johndoe
Note that this command will only delete the user's account and home directory, but it will not delete any files or directories owned by the user.
Working with Groups
To create a new group, you can use the groupadd
command followed by the desired group name. For example, to create a group named "developers", you would enter:
sudo groupadd developers
You can add users to a group using the usermod
command with the -aG
option, as shown earlier. For example, to add the user "johndoe" to the "developers" group, you would enter:
sudo usermod -aG developers johndoe
You can also remove a user from a group using the gpasswd
command. For example, to remove the user "johndoe" from the "developers" group, you would enter:
sudo gpasswd -d johndoe developers
To delete a group, you can use the groupdel
command followed by the group name:
sudo groupdel developers
Note that this command will only delete the group. Any files or directories owned by the group will not be deleted.
Conclusion
Managing users and groups is an essential task for system administrators. By creating and managing users and groups, you can control access to the system and its resources, ensuring that only authorized users can access sensitive data or perform critical tasks.