Table of Contents#
- Prerequisites
- Understanding UserDir
- Enabling UserDir in Zentyal
- Configuring User Public Directories
- Password Protecting Web Directories
- Testing the Configuration
- Troubleshooting Common Issues
- Conclusion
- References
1. Prerequisites#
- A Zentyal server with the Web Server module enabled (verify via Zentyal GUI: Modules → Web Server).
- Administrative access (GUI or SSH) to the Zentyal server.
- User accounts created (e.g.,
john) for whom you want to enable UserDir. - Basic knowledge of Linux permissions, Apache configuration, and (optional) SELinux.
2. Understanding UserDir#
The mod_userdir Apache module lets users publish web content from a public_html directory in their home folder (e.g., /home/john/public_html). Accessible via http://server/~username, this is ideal for personal sites, file sharing, or development. Password protection (via mod_auth_basic) restricts access to sensitive subdirectories.
3. Enabling UserDir in Zentyal#
Zentyal’s web server is Apache-based. Enable mod_userdir and configure UserDir via the GUI or command line.
3.1 Via Zentyal GUI#
- Log in to Zentyal (https://server:8443).
- Navigate to Modules → Web Server → Extra Configuration.
- Add the following Apache directives:
<IfModule mod_userdir.c> UserDir public_html # Use public_html in home directories UserDir disabled root # Disable for root (security) <Directory /home/*/public_html> AllowOverride All # Enable .htaccess for password protection Require all granted # Allow access to the directory </Directory> </IfModule> - Save changes and restart the web server (Zentyal prompts for restarts).
3.2 Via Command Line (Advanced)#
If the GUI method is insufficient, use Apache’s command-line tools:
-
Enable
mod_userdir:sudo a2enmod userdir -
Create a custom Apache config (e.g.,
/etc/apache2/conf-available/userdir.conf):sudo nano /etc/apache2/conf-available/userdir.confAdd:
<IfModule mod_userdir.c> UserDir public_html UserDir disabled root <Directory /home/*/public_html> AllowOverride All Require all granted </Directory> </IfModule> -
Enable the config and restart Apache:
sudo a2enconf userdir sudo systemctl restart apache2
4. Configuring User Public Directories#
For each user (e.g., john), create a public_html directory and set permissions.
4.1 Directory Creation & Permissions#
-
Create
public_html:
As the user (or root):sudo su - john # Switch to user john mkdir public_html # Create public_html exit # Return to root -
Set Permissions:
- Home directory (
/home/john): Must be executable by Apache (userwww-data). Set to755:sudo chmod 755 /home/john public_htmldirectory: Also755(web server can traverse/read):sudo chmod 755 /home/john/public_html- Files (e.g.,
index.html): Set to644(web server can read):sudo nano /home/john/public_html/index.html # Add content (e.g., "Hello!") sudo chmod 644 /home/john/public_html/index.html sudo chown john:john /home/john/public_html/index.html
- Home directory (
4.2 SELinux Considerations (if enabled)#
If SELinux is enforcing, allow Apache to read user home directories:
sudo setsebool -P httpd_enable_homedirs on # Persist across reboots
sudo chcon -R -t httpd_user_content_t /home/*/public_html # Label content4. Configuring User Public Directories#
(Repeat for each user, e.g., john.)
5. Password Protecting Web Directories#
To restrict access to a subdirectory (e.g., ~/public_html/private), use mod_auth_basic and a .htaccess file.
5.1 Enable .htaccess Support#
Ensure AllowOverride All is set in the Apache config for public_html (done in Step 3).
5.2 Create a Password-Protected Directory#
As the user, create a subdirectory to protect:
sudo su - john
mkdir public_html/private
exit5.3 Create a .htaccess File#
In the protected directory, create a .htaccess file:
sudo nano /home/john/public_html/private/.htaccessAdd:
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /home/john/.htpasswd # Password file (outside web root)
Require valid-user # Require a valid user from the file5.4 Generate User Credentials with htpasswd#
Create a password file (e.g., /home/john/.htpasswd) and add a user:
sudo htpasswd -c /home/john/.htpasswd john # -c creates a new file; omit for existing- Enter a password for
john. Omit-cto add/modify users later.
5.5 Set Permissions on .htpasswd#
Ensure Apache can read the file, but others cannot:
sudo chmod 640 /home/john/.htpasswd # Web server (www-data) can read
sudo chown www-data:john /home/john/.htpasswd # Adjust user/group as needed6. Testing the Configuration#
-
Access User Directory:
Navigate tohttp://server/~johnin a browser. You should see theindex.htmlcontent. -
Verify Password Protection:
Accesshttp://server/~john/private. You should be prompted for a username/password. Enterjohnand the password set inhtpasswd—you should see the (empty)privatedirectory (or a file inside).
7. Troubleshooting Common Issues#
- Permission Errors: Ensure
/home/john(755),public_html(755), and files (644) have correct permissions. - SELinux Blocking: Run
sudo getenforce—ifEnforcing, useaudit2allowto fix denials. - .htaccess Not Working: Verify
AllowOverride Allin the Apache config forpublic_html. - UserDir Not Loading: Check
mod_userdiris enabled (sudo a2enmod userdir) andUserDiris configured.
8. Conclusion#
Enabling UserDir and password protection on Zentyal’s web server empowers users to host personal content securely. For production, use HTTPS to protect credentials. Regularly audit permissions and configurations to maintain security.
9. References#
- Zentyal Documentation: https://doc.zentyal.org/
- Apache
mod_userdir: https://httpd.apache.org/docs/2.4/mod/mod_userdir.html - Apache Authentication: https://httpd.apache.org/docs/2.4/howto/auth.html
- SELinux HTTPD Guide: https://wiki.centos.org/HowTos/SELinux#HTTPD
htpasswdDocumentation: https://httpd.apache.org/docs/2.4/programs/htpasswd.html
This blog is licensed under CC BY 4.0. Adapted from official Apache and Zentyal documentation.