Wednesday, July 30, 2014

note on web server

Note: Below tips are based on CentOS (member of RedHat family, incl. Fedora). For other systems, like Debian/Ubuntu/Mint/SUSE/Mac OS, this may not work.

1. How to add new users?

$ sudo vi /etc/group 
and find line with 
users:x:100:xxx,yyy,zzz
and add new username behind. 

* for an independent system (unlike ours which is a virtual server attached to the main cluster), you may want to use useradd <username> to add new users. See detail here.

2. How to Enable Userdir (Public_html)?

$ sudo vi /etc/httpd/conf/httpd.conf 
and find the following part and 
<IfModule mod_userdir.c>
    #UserDir disabled
    UserDir enabled xxx yyy zzz
    UserDir public_html
</IfModule>

then restart apache by
$ sudo /etc/rc.d/init.d/httpd restart

Now you should be able to see the file content:
http://yourdomain.name/~xxx

If you got a 403 error, you should change the folder/file permission to 0755 and 0644, respectively. 

3. How to change permission to a folder and all of its subfolders and files?

To set the directories to 755 and set the files to 644, you can use the find command. For example:
To change all the directories to 755 (-rwxr-xr-x):
find ~/public_html/myfolder -type d -exec chmod 755 {} \;
To change all the files to 644 (-rw-r--r--):
find ~/public_html/myfolder -type f -exec chmod 644 {} \;
Ref: http://stackoverflow.com/questions/3740152/how-to-set-chmod-for-a-folder-and-all-of-its-subfolders-and-files-in-linux-ubunt

4. How to set password for Userdir (Public_html)?

Change to and/or specify directory to protect in /etc/httpd/conf/httpd.conf:
<Directory /home/xxx/public_html>
     AllowOverride All
</Directory>
               
OR
<Directory /home/xxx/public_html>
     AllowOverride AuthConfig
</Directory>
Create a file /home/xxx/public_html/.htaccess in that director that looks something like this:
     AuthName "Add your login message here."
     AuthType Basic
     AuthUserFile /home/xxx/public_html/.htpasswd
     AuthGroupFile /dev/null
     require user name-of-user
In this case the "name-of-user" is the login name you wish to use for accessing the web site.

Create (or clobber if it already exists) the password file /home/xxx/public_html/.htpasswd using the program htpasswd:
htpasswd -c .htpasswd name-of-user
Add a new user to the existing password file:
htpasswd .htpasswd name-of-user
Password file protection, ownership attributes:
File privileges: chmod ug+rw .htpasswd
File ownership: chown apache.apache .htpasswd

More method on encrypting a site can be found here: http://www.yolinux.com/TUTORIALS/LinuxTutorialApacheAddingLoginSiteProtection.html
Updating...

No comments:

Post a Comment