13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 7 ■ WORKING WITH APACHEaddresses is allowed (line 06). Note that it works rather like a regular expression, in that it’ll match onlywhatever is provided. So, this line allows any IP address of the form 192.168.*.*. <strong>Problem</strong> solved.But maybe you’d like your local users to be able to access these pages from home as well. In thiscase, you can add an alternative way of accessing these pages by setting up a special local user. The.htaccess file should look like this:AuthUserFile /etc/apache2/.htpasswdAuthName Local PagesAuthType BasicSatisfy Anyorder deny,allowdeny from allallow from 192.168.require user localNote the Satisfy Any directive; this means you can either be in the correct IP range (you can alsospecify by domain) or have the correct username and password. The default is Satisfy All, which wouldmean that you’d need both to be in the correct domain and to have the correct credentials.For setting the username up, the key point is the AuthUserFile directive, which sets up a file thatApache will check for the password of your user local as set up in the LIMIT section.The next step is to create the htpasswd file, using this command:htpasswd -c /etc/apache2/.htpasswd local■ Note The -c switch is used only to create the file. If you go to add another user, just use htpasswd/etc/apache2/.htpasswd otheruser.You’ll be challenged for the password for the user, which will be encrypted and put in the file. Makesure that only the Apache2 user can read this file:chown www-data /etc/apache2/.htpasswd; chmod og-r /etc/apache2/.htpasswd■ Note The .htpasswd file can live wherever you like, but for security reasons it should not live anywhere in yourweb data directories. Keep it instead with your Apache2 config. In this case, it doesn’t need to be a dot file(.htpasswd) because it won’t be visible to the average user anyway; you can just call it htpasswd.Now try loading a page in that directory from an IP address outside your local subnet; you should bechallenged for the username and password. Enter them, and you’re allowed in. Pass this username andpassword on to the users you want to be able to access your machine.168Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!