Again we'll be editing the httpd config file (etc/httpd/conf/httpd.conf). Make sure that you have the following directives set:
UserDir public_htmlAnd then simply uncomment the example provided, which will give you read access to the user files:
# UserDir disabled
<Directory /home/*/public_html>You'll now need to create a public_html directory for all users and make sure that permissions and SELinux are configured correctly. This is for a user called myuser.
AllowOverride FileInfo AuthConfig Limit
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
mkdir /home/myuser/public_html;chmod 701 /home/myuser; chmod 705 /home/myuser/public_htmlNow create a test page and give it the right permissions:
echo 'A Simple User Page' >> public_html/index.html; chmod 604 public_html/index.htmlFinally, set the SELinux settings to enable home directories:
setsebool -P httpd_enable_homedirs 1and change the user contexts to the Apache user context (you can get this command from the manual page for httpd_selinux):
chcon -R -t httpd_sys_content_t /home/myuser/public_htmlRestart Apache and you should be able to visit myuser's fancy page:
elinks 127.0.0.1/~myuserYou can create by public_html directory and even a simple page for all new users by modifying the skeleton directory, like so:
mkdir /etc/skel/public_htmlThis only helps for new users, but for existing users the process could be scripted like this:
echo 'A Simple User Page' >> public_html/index.html;
chmod -R 705 /etc/skel/public_html/
#!/bin/bash
if [ -n "$1" ]This script can be improved by looping through the accounts and checking that public_html does not exist, but it does the work.
then
user=$1
else
echo "Usage prepare username"
exit
fi
##Set appropriate permissions for home directory
chmod 701 /home/$user
##Create public_html
mkdir /home/$user/public_html
##Create Index.html file
echo "A Simple User Page for $user" >> /home/$user/public_html/index.html;
##Change permissions and ownership
chown -R $user:$user /home/$user/public_html
chmod -R 705 /home/$user/public_html/
##Change SELinux context
chcon -R -t httpd_sys_content_t /home/$user/public_html
No comments:
Post a Comment