Lighttpd Protect Different Directories With Different Password Files
There is a way to protect different directories with different username/password under Lighttpd server.
If you use different userfile files for authenticating in different directories, you can attach each to the correct directory by using conditionals.
Let us see how to protect two different directories using conditionals directives:
/docs/ with username tom
/sales/ with username jerry
Open lighttpd configuration file:
# vi lighttpd.conf
Make sure mod_auth is loaded:
server.modules += ( "mod_auth" )
Now add first conditionals directive to protect /docs/:
$HTTP["url"] =~ "^/docs/" {
auth.backend = "plain"
auth.backend.plain.userfile = "/home/lighttpd/.lighttpdpassword-DOCS"
auth.require = ( "/docs/" =>
(
"method" => "basic",
"realm" => "Password protected area",
"require" => "user=tom"
)
)
}
Add second conditionals directive to protect /sales/:
$HTTP["url"] =~ "^/sales/" {
auth.backend = "plain"
auth.backend.plain.userfile = "/home/lighttpd/.lighttpdpassword-SALES"
auth.require = ( "/sales/" =>
(
"method" => "basic",
"realm" => "Password protected area",
"require" => "user=jerry"
)
)
}
Save and close the file. Now create a password for tom user:
# vi /home/lighttpd/.lighttpdpassword-DOCS
Append username:password for tom:
tom:TomsPassword
Save and close the file. Also, create a password for jerry user:
vi /home/lighttpd/.lighttpdpassword-SALES
Append username:password for jerry:
jerry:JerrysPassword
Save and close the file. Restart lighttpd:
# /etc/init.d/lighttpd restart
E-mail this to a Friend
Printable Version
You may also be interested in other helpful articles:
- Howto: Protect account against a password cracking attack
- Howto set or force user to change a password at first login under Linux
- Lighttpd setup a password protected directory (directories)
- Linux Password trick with immutable bit using chattr command
- Linux turn OFF password expiration / aging
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: /etc/lighttpd/lighttpd.conf, lighthttpd password, lighttpd auth, lighttpd auth.require, lighttpd authentication, lighttpd basic auth, lighttpd mod_auth, lighttpd password, lighttpd password protection



Recent Comments
Yesterday ~ 12 Comments
Yesterday ~ 8 Comments
Yesterday ~ 185 Comments
Yesterday ~ 15 Comments
Yesterday ~ 3 Comments