How to configure htaccess authentication in Squid proxy

This tutorial explains the steps to configure squid proxy in Linux server.

Step1: Create a username/password

First create a NCSA password file using htpasswd command. htpasswd is used to create and update the flat-files used to store usernames and password for basic authentication of squid users.

#htpasswd /etc/squid/passwd user1
New password:
Re-type new password:
Adding password for user user1

Make sure squid can read passwd file:

#chmod o+r /etc/squid/passwd

Step2: Locate nsca_auth authentication helper

Usually nsca_auth is located at /usr/lib/squid/ncsa_auth. You can find out location using rpm (Redhat,CentOS,Fedora) or dpkg (Debian and Ubuntu) command:

#dpkg -L squid | grep ncsa_auth

If you are using RHEL/CentOS/Fedora Core or RPM based distro try:

#rpm -ql squid | grep ncsa_auth

Step3: Configure nsca_auth for squid proxy authentication

Now open /etc/squid/squid.conf file

# vi /etc/squid/squid.conf

Append (or modify) following configration directive:

auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/passwd
auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 2 hours
auth_param basic casesensitive off

Also find out your ACL section and append/modify

acl ncsa_users proxy_auth REQUIRED
http_access allow ncsa_users

Save and close the file.

Restart squid:

#/etc/init.d/squid restart

Leave a Reply