When setting up a shared projects folder for multi-user access to all the code we're developing on your VPS and where multiple users have their own accounts, we’ll want to choose a location that is accessible to all users but also secure. Here’s how we can achieve this on our Ubuntu 24.04 VPS:
A good place to store the shared code folder is within the /opt directory, which is typically used for optional software packages and can be a good place for shared resources.
For example, we can create the directory /opt/projects.
First, create the directory where the code will be stored:
sudo mkdir /opt/projectsNext, create a group that all users who need access to the code folder will be added to. This allows for group-based access control.
sudo groupadd devsChange the group ownership of the directory to the new devs group:
sudo chown :devs /opt/projectsSet the permissions on the directory so that the group members have read, write, and execute permissions:
sudo chmod 2775 /opt/projects- The
2in2775ensures that any files or directories created within the/opt/projectsdirectory inherit the group ownership. - The
775ensures that the owner and group members can read, write, and execute files, while others can only read and execute.
For each user that needs access to the shared folder, add them to the devs group:
sudo usermod -aG devs usernameReplace username with the actual username of each user who needs access.
After setting up, verify the permissions by logging in as a different user and ensuring they can access and create files in /opt/projects.
- Backup: Regularly back up the contents of
/opt/projectsto prevent data loss. - Monitoring: Consider using monitoring tools to track access to the shared folder if security or auditing is a concern.
- Advanced Permissions: For more granular control, we could look into using ACLs (Access Control Lists) instead of basic Unix permissions.