Proxy Squid: User Authentication

Let us introduce how to use user authentication in Squid proxy. Therefore, in this configuration, only authenticated users can access WEB browsing.

Remember that this is our third post about squid proxy. Thus, we start from the point that the reader already knows the commands and settings previously presented.

At the end of the post we will have links to previous articles.

1) Installing apache2-utils

Initially, assuming squid is already installed. Let’s install apache2-utils.

sudo apt install apache2-utils 

or 

sudo yum install httpd-tools 

2) Creating user and password file

Let’s create a file where we will keep user and password data.

sudo htpasswd -c /etc/squid/squid_password joao 

The “-c” will create the file and will introduce the user joao. However, to add new users, it is not necessary to include the “-c” option. Thus, to add a new user maria, we can type:

sudo htpasswd /etc/squid/squid_password maria 

Best Practices and Rules for Usernames and Passwords

When registering users in the password file, pay close attention to a few syntax rules to avoid silent authentication failures in the browser:

  • Case Sensitivity: Both Squid and the basic_ncsa_auth helper are strictly case-sensitive for both usernames and passwords. If you create the user as Joao, the client will fail to authenticate when typing joao. Pro Tip: Standardize all usernames in lowercase only (e.g., joao, maria, admin) to prevent unnecessary support tickets.
  • Using Numbers: Fully supported for both usernames and passwords (e.g., user01, support2). Combining numbers and special characters in passwords significantly strengthens security.
  • No Whitespace: The Squid authentication helper uses spaces as internal delimiters between the username and password. Never use spaces in usernames (e.g., use joao_silva or joaosilva, never joao silva).
  • Avoid Colons (:): The file generated by htpasswd uses : to separate the username from the password hash (username:hash). Including a colon inside the username breaks the line formatting.
  • Avoid Accented Characters and Non-ASCII Symbols (ç, ã, é): Different browsers and operating systems may send conflicting encodings over HTTP Basic authentication (UTF-8 vs. ISO-8859-1). As a result, a password with special characters might work on one device and fail on another.

Optional Security Tip: By default, the password file is created with world-readable permissions (644). To prevent other local users from viewing the password hashes while ensuring only the Squid service can read it, restrict ownership and permissions:

sudo chown root:proxy /etc/squid/squid_password   
sudo chmod 640 /etc/squid/squid_password

On Debian/Ubuntu use “root:proxy” (use root:squid on RHEL/CentOS).

We can check the encrypted password file:

cat squid_password 

joao:$apr1$8jtduIhgh88PImX5o14XC2KPF1%k54v/ 

maria:$apr1$wCB778*i186c5O5KK5ZA4/7A/VI7&*/ 

3) Testing users in Proxy Squid

Let’s look for the basic_ncsa_auth file.

sudo find / -name "basic_ncsa_auth" 2>/dev/null

It’s usually in /usr/lib/squid/ or in /usr/lib/squid3/ or in /usr/lib64/squid/

In our case it’s in: /usr/lib/squid/basic_ncsa_auth .

Remember to replace it with where your “basic_ncsa_auth” is.

Now let’s test users and passwords. For this we will type the command below.

/usr/lib/squid/basic_ncsa_auth /etc/squid/squid_password

After entering the command, enter the username and password

joao joao123 

OK 

maria maria123 

OK 

OK indicates that everything is fine with the password file and its users.

4) Configuring squid.conf

Now let’s introduce the rule into squid.conf. Let’s take advantage of the configuration file used in the post: Squid Proxy Installation and Configuration.

acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl CONNECT method CONNECT
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_port 3128
#----------------------------

#(1)
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/squid_password

#(2)
auth_param basic realm Proxy Simplificando Redes

#(3)
acl usersquid proxy_auth REQUIRED

#(4)
http_access allow usersquid

#----------------------------
http_access deny all

(1) Defines the location “basic_ncsa_auth” and the password+user file we created. Remember to check the location of basic_ncsa_auth.

(2) “auth_param basic realm” demonstrates the proxy protection reported to the client. In our case it will be”Proxy Simplificando Redes”

(3) We created a usersquid ACL that indicates it requires user authentication.

(4) http_access allow usersquid , we allow http access for authenticated users from ACL usersquid.

Let’s test it on the Client

Client firefox configuration

List of the Squid and SquidGuard tutorial:

Lesson 1: Squid Proxy Installation and Configuration

Lesson 2: Squid Proxy: Filter clients by IP and MAC

Lesson 3: Squid: User Authentication

Lesson 4: SquidGuard : Installation and Configuration

Lesson 5: SquidGuard : how to import blocklist

More posts

Squid Proxy Installation and Configuration

Squid Proxy: Filter clients by IP and MAC

SquidGuard : Installation and Configuration

Juliana Mascarenhas

Data Scientist and Master in Computer Modeling by LNCC.
Computer Engineer