Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i am in need of password protecting a folder on my apache web server. how can i set it up to ask for user and password before the user is granted access to the folder?
Then create the htpasswd file, and add at least one user to it (as root):
Code:
htpasswd -c /var/www/htpasswd username
This file should be outside of the directories available from the web (I'm assuming here that your document root is /var/www/htdocs - modify as necessary). You would need to have mod_auth enabled.
Note that Basic authentication is not secure (all credentials are transmitted as plain text). There is also AuthType digest (implemented in mod_auth_digest), which hashes the credentials before sending, though this is not so well supported by browsers and a little more complex.
Note that Basic authentication is not secure (all credentials are transmitted as plain text). There is also AuthType digest (implemented in mod_auth_digest), which hashes the credentials before sending, though this is not so well supported by browsers and a little more complex.
+1 on digest authentication. It's not much more effort than basic, and it's more secure.
Carefully read the documentation and post back if you run into issues.
<Directory "/var/www/html/music">
AuthType Basic
AuthName "My music Directory"
AuthUserFile "/var/www/htpasswd"
Require valid-user
</Directory>
and that part works with no problem, buti need help with the auth part... i made the .htpasswd file and put it in a htpasswd folder located at /var/www/htpasswd but wont auth . the user is music and this is what the file looks like.
But are you saying you put that line in a file called /var/www/htpasswd/.htpasswd? htpasswd is a command to create apassword file (or add users, etc). See man htpasswd.
If you want to create an authorized user "music" with password "password", the command
htpasswd -c /var/www/htpasswd music password
will create a file /var/www/htpassword containing user and password information for "music". Your authentication against /var/www/htpasswd should then work (or if it doesn't, the problem is somewhere else).
Edit - if you've created a directory called /var/www/htpasswd, you should probably get rid of it first, since htpasswd will try to create a file with the same name and fail.
That line is a command that you type from the terminal - it doesn't go into a file. It's like "ls" or "cd" commands.
You don't want a folder (directory) called htpasswd in /var/www - delete it. The command above will create a file of that name itself (that's what the -c option does - it stands for "create the following file").
From the command line in a terminal sesion, type "man htpasswd" to see what I mean - type "q" to quit.
htpasswd -n[mdps] username
htpasswd -nb[mdps] username password
-c Create a new file.
-n Don't update file; display results on stdout.
-m Force MD5 encryption of the password.
-d Force CRYPT encryption of the password (default).
-p Do not encrypt the password (plaintext).
-s Force SHA encryption of the password.
-b Use the password from the command line rather than prompting for it.
-D Delete the specified user.
On Windows, NetWare and TPF systems the '-m' flag is used by default.
On all other systems, the '-p' flag will probably not work.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.