Permissions, users and groups

"I am currently a Software Engineering student at ALX. I'm passionate about technology and enjoy conducting research to find answers on my own. I have a natural inclination to ask 'WHY' more often than 'HOW'.
"While working on projects at ALX, I have acquired a wealth of interesting and diverse knowledge about software engineering and computer science in general. Therefore, I needed a place to store and save all this information, allowing me to refer back to it whenever I forget."
Imagine you have a Linux system with multiple users, and you want to manage access to a specific directory called /project. You want to give some users read and write access to the /project directory, while others should have read-only access. To do this efficiently, you can use groups.
Here's how you might use groups to manage access:
Create Groups:
First, you create two groups:
project_rwfor users who should have read and write access andproject_rofor users who should have read-only access.sudo groupadd project_rw sudo groupadd project_roAdd Users to Groups:
Next, you add users to the appropriate groups. For example:
sudo usermod -aG project_rw user1 sudo usermod -aG project_rw user2 sudo usermod -aG project_ro user3 sudo usermod -aG project_ro user4user1anduser2are added to theproject_rwgroup, which means they have read and write access to the/projectdirectory.user3anduser4are added to theproject_rogroup, which means they have read-only access to the/projectdirectory.
Set Directory Ownership:
You can set the ownership of the
/projectdirectory to a specific user (e.g.,project_owner) and theproject_rwgroup:sudo chown project_owner:project_rw /projectThis means that the owner (
project_owner) has full control over the directory, and theproject_rwgroup has group ownership.Set Directory Permissions:
Finally, you can set the permissions on the
/projectdirectory to control access:sudo chmod 770 /project7for the owner: This grants read (4), write (2) and execute (1) permissions, so the owner can read, write and execute on the directory.7for the group: This also grants read (4) and write (2) permissions to the group, so members ofproject_rwcan read and write to the directory.0for others: This means others (users not in the owner or group) have no permissions on the directory.
With this setup, user1 and user2 (members of the project_rw group) can read and write to the /project directory, while user3 and user4 (members of the project_ro group) can only read from it.
In summary, groups allow you to manage permissions more effectively by grouping users with similar access needs and applying permissions to those groups, which simplifies access control and file management on a Linux system.
How to add multiple users in a linux system
Creating a Linux system with multiple users involves setting up a Linux operating system, creating user accounts, and configuring permissions and groups. Here's a step-by-step guide on how to achieve this:
Install Linux:
Install a Linux distribution of your choice on a computer or a virtual machine. Popular Linux distributions include Ubuntu, Debian, CentOS, Fedora, and others.
Create a User:
During the installation process or after the installation is complete, you'll typically create a user. This user is often created with administrative privileges and can use
sudoto perform actions with superuser permissions.Add Additional Users:
After the initial user is created, you can add more users using the
adduseroruseraddcommand. For example, to add a user named "john":sudo adduser johnFollow the prompts to set a password and provide additional user information.
Grant Administrative Privileges:
If you want to grant administrative privileges to additional users, you can add them to the
sudogroup. On Ubuntu, members of thesudogroup can run commands with superuser privileges.sudo usermod -aG sudo johnManage User Groups:
Create and manage user groups as needed using the
groupadd,groupmod, andgroupdelcommands. For instance, to create a group called "developers":sudo groupadd developersAssign Users to Groups:
Assign users to groups using the
usermodcommand. For example, to add the user "john" to the "developers" group:sudo usermod -aG developers johnManage Permissions:
Set file and directory permissions based on user groups using
chmod. For example, to give the "developers" group read and write access to a directory:sudo chgrp developers /path/to/directory sudo chmod g+rw /path/to/directoryThis allows users in the "developers" group to read and write to the specified directory.
By following these steps, you can set up a Linux system with multiple users, each having their own user account and optionally belonging to various groups with specific permissions and access rights.



