π Secure Shared Logging: Creating a Centralized Logs Directory for Multiple Linux Users
π― Objective
In multi-user Linux environments, there are often requirements where several users must be able to submit logs or reports in a shared location β without having the ability to modify or delete each otherβs files. This project demonstrates how to configure such a secure, centralized directory called /central_logs.
π Project Overview
We aim to:
- Create a shared directory
/central_logs - Allow all users to write (add) their own files
- Prevent users from modifying or deleting each otherβs files
- Let all users list the contents of the directory
To simulate this, we will create two test users: user1 and user2.
βοΈ Step-by-Step Implementation
1οΈβ£ Create the Central Directory
sudo mkdir /central_logs2οΈβ£ Create Test Users
sudo useradd user1
sudo useradd user2
# Set passwords
sudo passwd user1
sudo passwd user2β Note: If the users already exist, skip this step.
3οΈβ£ Set Group Ownership and Permissions
Weβll use the Sticky Bit concept β commonly used in directories like /tmp.
sudo chmod 1777 /central_logsπ What does 1777 mean?
1β Sticky Bit: Only the file's owner or root can delete or rename their own files.7β Read, write, execute for owner7β Read, write, execute for group7β Read, write, execute for others
This allows:
- All users to write to the directory
- Only the owner of a file to modify or delete it
π§ͺ Testing and Verification
β
Switch to user1 and Create a File
su - user1
echo "Log file from user1" > /central_logs/user1_log.txtβ
Switch to user2 and Try to Delete user1's File
su - user2
rm /central_logs/user1_log.txtOutput:
rm: cannot remove '/central_logs/user1_log.txt': Operation not permittedπ Success! user2 cannot delete user1's file.
β
Now, Let user2 Create Their Own File
echo "Log file from user2" > /central_logs/user2_log.txtβ Both Users Can List Files
ls -l /central_logsExample output:
-rw-r--r-- 1 user1 user1 23 May 13 15:00 user1_log.txt
-rw-r--r-- 1 user2 user2 23 May 13 15:01 user2_log.txtπ Real-World Use Cases
- Log aggregation from multiple users/applications
- Shared reporting directory
- Assignment submissions in training environments
- Secure drop folders in enterprise settings.
π§ Bonus Tips
- Use ACLs (Access Control Lists) for even more granular permission control
- Monitor file activity using tools like
auditdorinotify
π Conclusion
This setup offers a simple yet powerful way to allow multiple users to collaborate by writing to a shared directory without compromising file integrity or security. Sticky Bit is your friend in scenarios like this!
