Install Squid Proxy with Auth on Ubuntu 24.04

By Anurag Singh

Updated on Dec 03, 2025

Install Squid Proxy with Auth on Ubuntu 24.04

In this tutorials, how to install Squid Proxy with Auth on Ubuntu 24.04.

What is Squid Proxy?

Squid is a powerful caching and forwarding proxy widely used for secure web filtering, performance optimization, and controlled internet access. On Ubuntu 24.04, Squid works smoothly with modern authentication methods, making it reliable for both personal and production environments. 

In this guide, we install Squid, enable user authentication, tighten the configuration, and test the service step by step.

Prerequisites

Before we begin, ensure we have the following:

How to Install Squid Proxy with Auth on Ubuntu 24.04

Step 1: Update System Packages

Keeping packages updated helps our proxy run on the latest stable base.

sudo apt update && sudo apt upgrade -y

Step 2: Install Squid

Ubuntu 24.04 provides the latest stable Squid package from official repositories.

sudo apt install squid -y

After installation, Squid runs automatically. We verify the status:

sudo systemctl status squid

Step 3: Install Apache htpasswd Tool for Authentication

Squid uses basic authentication via an external helper. We install the apache2-utils package to generate password files.

sudo apt install apache2-utils -y

Step 4: Create Authentication Password File

We create a dedicated directory to store credentials securely.

sudo mkdir -p /etc/squid/auth
sudo htpasswd -c /etc/squid/auth/squid_users username1

The command will prompt for a password and store it in encrypted form.

To add more users later, we omit -c:

sudo htpasswd /etc/squid/auth/squid_users username2

Step 5: Configure Squid for Authentication

We edit Squid’s main configuration file.

sudo nano /etc/squid/squid.conf

Find and replace following variables (Or your can take backup or existing squid.conf file, remove it and and create same file with following content):

###############################################################
# PORT
###############################################################
http_port 3128

###############################################################
# DEFAULT ACLs (KEEP THEM FIRST)
###############################################################
acl localnet src 0.0.0.1-0.255.255.255
acl localnet src 10.0.0.0/8
acl localnet src 100.64.0.0/10
acl localnet src 169.254.0.0/16
acl localnet src 172.16.0.0/12
acl localnet src 192.168.0.0/16
acl localnet src fc00::/7
acl localnet src fe80::/10

acl localhost src 127.0.0.1/32 ::1

acl SSL_ports port 443
acl Safe_ports port 80
acl Safe_ports port 21
acl Safe_ports port 443
acl Safe_ports port 70
acl Safe_ports port 210
acl Safe_ports port 1025-65535
acl Safe_ports port 280
acl Safe_ports port 488
acl Safe_ports port 591
acl Safe_ports port 777

acl manager proto cache_object

###############################################################
# DEFAULT SECURITY RULES
###############################################################
# Deny unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to non-SSL ports
http_access deny CONNECT !SSL_ports

# Allow localnet and localhost before anything else
http_access allow localnet
http_access allow localhost

# Cache manager access
http_access allow localhost manager
http_access deny manager

# Block link-local (recommended)
http_access deny to_localhost
http_access deny to_linklocal


###############################################################
# AUTHENTICATION
###############################################################
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/auth/squid_users
auth_param basic realm "Proxy Authentication Required"
auth_param basic credentialsttl 2 hours

acl authenticated proxy_auth REQUIRED

# Allow authenticated users
http_access allow authenticated


##############################################################
# FINAL RULE (ALWAYS LAST)
##############################################################
http_access deny all

include /etc/squid/conf.d/*.conf

Save and exit the file.

This configuration ensures our proxy requires valid credentials before granting access.

Step 6: Test Squid Configuration

Before restarting, we validate the syntax.

sudo squid -k parse

If no errors appear, we reload the service:

sudo systemctl restart squid

We confirm that Squid is active:

sudo systemctl status squid

Step 7: Allow Squid Through Firewall (UFW)

If UFW is enabled, we allow the proxy port.

sudo ufw allow 3128/tcp

Reload:

sudo ufw reload

Step 8: Test Proxy Access

We test from any device or browser by setting the proxy to:

IP: SERVER_IP

Port: 3128

Once configured, any request should prompt for the username and password created earlier.

To test via terminal:

curl -x http://username1:password@SERVER_IP:3128 https://www.hostmycode.com -I

For locally test:

curl -x http://127.0.0.1:3128 https://www.hostmycode.com -I

A valid response confirms working authentication.

Step 9: Optional — Restrict Access by IP Range

Sometimes we prefer an extra layer of control.

Edit Squid config:

sudo nano /etc/squid/squid.conf

Add before http_access allow authenticated:

acl allowed_ips src 192.168.1.0/24
http_access allow allowed_ips

Reload:

sudo systemctl restart squid

Conclusion

We installed and configured Squid Proxy on Ubuntu 24.04 with secure user authentication using NCSA password management. Our setup now offers controlled access, reliable filtering, and a strong foundation for performance-optimized proxy operations.

For teams managing production environments or individuals who need stable and secure browsing control, this proxy setup provides a dependable, modern workflow.