To understand and apply essential Linux commands for user and group management, file ownership, and permissions to effectively administer a multi-user environment.
Imagine you are the Linux administrator for a software company "TechWave Solutions" that uses Linux servers to manage projects. You need to ensure proper user access, secure file ownership, and organized group management for three teams working on:
- DataBridge - A data analytics tool.
- CodeFusion - A collaborative coding platform.
- SecureVault - A secure document management system.
You need to:
- Assign users to the correct groups.
- Configure file permissions for project directories.
- Secure resources by assigning appropriate ownership.
Each project team will have its own group for better organization and security.
# Create groups for each project team
sudo groupadd databridge_team
sudo groupadd codefusion_team
sudo groupadd securevault_team
# Create user accounts and assign them to primary groups
sudo useradd -g databridge_team amit
sudo useradd -g codefusion_team priya
sudo useradd -g securevault_team rajSome users work on multiple projects and need access to other groups.
# Add users to secondary groups
sudo usermod -a -G codefusion_team amit
sudo usermod -a -G securevault_team priyaCheck group membership for each user to ensure proper assignment.
# Check groups for each user
groups amit
groups priyaSet up directories for each project and assign group ownership.
# Create project directories
sudo mkdir /projects/databridge
sudo mkdir /projects/codefusion
sudo mkdir /projects/securevault
# Set group ownership
sudo chown :databridge_team /projects/databridge
sudo chown :codefusion_team /projects/codefusion
sudo chown :securevault_team /projects/securevault
# Set permissions for group collaboration
sudo chmod 770 /projects/databridge
sudo chmod 770 /projects/codefusion
sudo chmod 770 /projects/securevaultAssign ownership of existing files to appropriate users or groups.
# Assign ownership of project files
sudo chown amit:databridge_team /projects/databridge/datafile.txt
sudo chown priya:codefusion_team /projects/codefusion/codefile.txtConfigure a global directory accessible to all users for shared resources.
# Create a shared directory
sudo mkdir /projects/shared
# Set permissions for global access
sudo chmod 777 /projects/sharedEnsure users have secure passwords.
# Set or change user passwords
sudo passwd amit
sudo passwd priya-
Least Privilege Principle: Assign the minimum permissions required for users to perform their roles to enhance security.
-
File Ownership and Permissions: Use
chownandchmodto manage ownership and permissions effectively. -
Audit and Monitoring: Periodically verify user and group assignments using
groupsandls -lcommands. -
Access Control Lists (ACLs): For more granular permissions, use ACLs (
setfaclandgetfacl). -
Documentation: Maintain proper documentation for user roles, groups, and permission configurations.
By following the steps above, the Linux administrator ensures:
- Proper segregation of users and teams.
- Secure access to project files and directories.
- Enhanced collaboration across project teams.
T
You are the system administrator for a development team working on a shared Linux server. The team consists of developers, testers, and a project manager. Your goal is to create and manage user accounts, groups, and file permissions to ensure a secure and efficient working environment.
-
Initial Setup
The server needs to host the following groups:- dev_team: For developers.
- test_team: For testers.
- proj_mgmt: For the project manager.
Additionally, create the following directories:
/projects: Shared by all users./dev_projects: Accessible only to developers./test_reports: Accessible only to testers./management: Accessible only to the project manager.
Create the groups required for the team:
sudo groupadd dev_team
sudo groupadd test_team
sudo groupadd proj_mgmtAdd users to the system and assign them to their respective groups.
Developers:
durgaakshay
Testers:
rohitsejal
Project Manager:
radha
Commands:
sudo adduser durga
sudo usermod -a -G dev_team durga
sudo adduser akshay
sudo usermod -a -G dev_team akshay
sudo adduser rohit
sudo usermod -a -G test_team rohit
sudo adduser sejal
sudo usermod -a -G test_team sejal
sudo adduser radha
sudo usermod -a -G proj_mgmt radhaSet up directories and assign permissions based on group membership:
sudo mkdir /projects
sudo mkdir /dev_projects
sudo mkdir /test_reports
sudo mkdir /management
# Set ownership and permissions
sudo chown :dev_team /dev_projects
sudo chmod 770 /dev_projects
sudo chown :test_team /test_reports
sudo chmod 770 /test_reports
sudo chown :proj_mgmt /management
sudo chmod 770 /management
# Make /projects accessible to everyone
sudo chmod 777 /projectsLog in as different users and verify their access:
# Switch to durga and check access
su - durga
cd /dev_projects # Should succeed
cd /test_reports # Should fail
exit
# Switch to sejal and check access
su - sejal
cd /test_reports # Should succeed
cd /dev_projects # Should fail
exitIf a tester (e.g., rohit) is promoted to a developer role:
- Remove
rohitfromtest_team. - Add
rohittodev_team.
Commands:
sudo gpasswd -d rohit test_team
sudo usermod -a -G dev_team rohitVerify the change:
groups rohitEnsure all users have strong passwords and update passwords as needed:
-
For user
akshay:sudo passwd akshay
-
For all users (force password change at next login):
sudo passwd -e durga akshay rohit sejal radha
-
List all users and groups:
cat /etc/passwd cat /etc/group
-
Check group memberships:
groups durga groups sejal
- Secure Access: Only authorized users can access specific directories.
- Proper Group Management: Teams are correctly grouped, simplifying permission assignments.
- Efficient User Modifications: Easily modify roles or permissions as team structures change.
- Password Security: Users follow strong password policies.
You are responsible for setting up and managing a Linux server for a software company that develops and maintains multiple software products. Each product has its own dedicated teams of developers, testers, and managers. Your task is to organize user accounts, groups, file permissions, and project-specific directories to ensure a secure and efficient working environment.
The company manages the following software products:
- FinTrack: A personal finance management app.
- EduConnect: An online learning platform.
- HealthSync: A health and fitness tracking application.
Each product has:
- Developers: Require full access to project code.
- Testers: Require access to testing resources.
- Managers: Require read-only access for monitoring.
/projects/fintrack/projects/educonnect/projects/healthsync
Create groups for developers, testers, and managers for each product:
sudo groupadd fintrack_devs
sudo groupadd fintrack_testers
sudo groupadd fintrack_managers
sudo groupadd educonnect_devs
sudo groupadd educonnect_testers
sudo groupadd educonnect_managers
sudo groupadd healthsync_devs
sudo groupadd healthsync_testers
sudo groupadd healthsync_managersAssign users to appropriate groups based on their roles and products:
- FinTrack:
- Developers:
vikas,anjali - Testers:
kiran,priya - Manager:
rahul
- Developers:
sudo adduser vikas
sudo usermod -a -G fintrack_devs vikas
sudo adduser anjali
sudo usermod -a -G fintrack_devs anjali
sudo adduser kiran
sudo usermod -a -G fintrack_testers kiran
sudo adduser priya
sudo usermod -a -G fintrack_testers priya
sudo adduser rahul
sudo usermod -a -G fintrack_managers rahulRepeat similar steps for users in EduConnect and HealthSync:
-
EduConnect:
- Developers:
rohit,sweta - Testers:
amit,riya - Manager:
neha
- Developers:
-
HealthSync:
- Developers:
akash,tanvi - Testers:
sheetal,deepak - Manager:
meera
- Developers:
Set up directories for each product:
sudo mkdir -p /projects/fintrack
sudo mkdir -p /projects/educonnect
sudo mkdir -p /projects/healthsyncAssign ownership and permissions to ensure secure access:
-
FinTrack:
sudo chown :fintrack_devs /projects/fintrack sudo chmod 770 /projects/fintrack setfacl -m g:fintrack_testers:r-x /projects/fintrack setfacl -m g:fintrack_managers:r-- /projects/fintrack
-
EduConnect:
sudo chown :educonnect_devs /projects/educonnect sudo chmod 770 /projects/educonnect setfacl -m g:educonnect_testers:r-x /projects/educonnect setfacl -m g:educonnect_managers:r-- /projects/educonnect
-
HealthSync:
sudo chown :healthsync_devs /projects/healthsync sudo chmod 770 /projects/healthsync setfacl -m g:healthsync_testers:r-x /projects/healthsync setfacl -m g:healthsync_managers:r-- /projects/healthsync
Log in as different users to ensure permissions are correctly configured:
-
As a developer (
vikas):su - vikas cd /projects/fintrack # Should succeed touch test_file.txt # Should succeed exit
-
As a tester (
kiran):su - kiran cd /projects/fintrack # Should succeed ls # Should succeed touch test_file.txt # Should fail exit
-
As a manager (
rahul):su - rahul cd /projects/fintrack # Should succeed ls # Should succeed touch test_file.txt # Should fail exit
If a new developer (nisha) is added to HealthSync:
sudo adduser nisha
sudo usermod -a -G healthsync_devs nishaVerify:
groups nishaCreate a shared directory /projects/shared for collaboration between all products:
sudo mkdir /projects/shared
sudo chmod 777 /projects/sharedThis directory will allow all users to read, write, and execute.
Periodically check the permissions and group memberships to ensure security:
# List directory permissions
ls -ld /projects/*
# Check group memberships
groups vikas
groups kiran
groups rahul- Secure Access Control: Each user has access only to the directories and permissions relevant to their role and product.
- Collaboration Efficiency: Shared resources are accessible to all without compromising product-specific security.
- Dynamic Management: New users, roles, and products can be easily added or modified.
- Practical Use of Commands: Utilized commands like
groupadd,usermod,chown,chmod, andsetfacl.