Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have setup LAMP on my ubuntu 12.04 system.I want to set password for all the files inside the root folder of Apache.So that only authorized person can use them.So how to set password for the folders for the apache?Any help and suggestions will be highly appreciable.

share|improve this question
    
Please update your question to clarify whether you want to password protect a site when accessed from the web or to protect files when accessed locally. –  Jo-Erlend Schinstad Aug 6 '12 at 7:58
    
I want to protect files when accessed locally –  newuser Aug 6 '12 at 11:57

2 Answers 2

You can use Basic authentication to do that. For example 1. Create a htpasswd file in apache folder (You can create this anywhere)

htpasswd -c /etc/apache2/passwd username

  1. Now add the below content to / directive

AuthType Basic

AuthName "By Invitation Only"

AuthUserFile /etc/apache2/passwd

Require valid-user

source: http://httpd.apache.org/docs/2.2/howto/auth.html

share|improve this answer
    
This is why I asked him to clarify the question. This is not what he wanted. –  Jo-Erlend Schinstad Aug 6 '12 at 16:09

You don't want to password protect the files in this instance, but rather decide who should be allowed to touch the files. It is the user accounts that should be protected with passwords (or other means like keys). Anything else would apply sharing passwords between users, which is Always Wrong.

What you want to do, is to set ownership of the files and directories. That's simple: chown -R www-data:groupname /siteroot (siteroot is the directory that contains the files you want to protect).

In the example above, I've set ownership to www-data because this user needs access in order for you to publish these files. I've set "groupname" as the group owner. You can use your own primary group, which is the same as your username. In this case, only you and the server will be able to manage those files.

If you want more than one local user to be able to manage the content, then you want to create a new group, add the relevant users to that group and make that the group owner. Let's say you want the existing users "joe", "john" and "gina" to be allowed to read and edit the files in the /var/www/ directory. Everyone else should have no access to that folder at all.


addgroup mysite-editors
adduser joe mysite-editors
adduser john mysite-editors
adduser gina mysite-editors
chown -R www-data:mysite-editors /var/www/*
chmod o-rwx -R /var/www

The last line is what removes "others" rights to read, access or write to any files in /var/www.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.