On this page
- What does an authenticated forward proxy give you?
- How do you install Squid and the password tool?
- How do you create proxy users?
- What should the configuration file contain?
- How do you check the syntax and start Squid?
- How do you limit which addresses may connect?
- How do you confirm authentication is enforced?
- How do browsers and tools use the proxy?
- How do you maintain Squid and solve common errors?
- Questions
What does an authenticated forward proxy give you?
A forward proxy makes outgoing web requests on behalf of its clients, so sites see the address of the VPS instead of yours. Useful cases include testing how a service looks from another city, giving a build machine one fixed outbound address that an external API can allow, or sending browser traffic from an untrusted network through a server you control. HTTPS stays encrypted end to end: the proxy only relays the tunnel opened with the CONNECT method.
A proxy without a login is an open relay that strangers will find and use for spam and abuse, and the complaints would land on your server. Everything in this guide therefore requires a username and password, and the firewall adds a second layer by accepting connections only from listed addresses. Examples use the server 198.51.100.24, port 3128 and a client at 203.0.113.50.
How do you install Squid and the password tool?
Both come from the standard repositories. On Ubuntu and Debian:
sudo apt update
sudo apt install -y squid apache2-utils
apt policy squidOn Rocky Linux 9 and AlmaLinux 9:
sudo dnf install -y squid httpd-tools
dnf info squidPrint the version and compile options with:
squid -v | head -2Note where the authentication helper lives, because the path goes into the configuration. Debian and Ubuntu install it as /usr/lib/squid/basic_ncsa_auth; Rocky and Alma use /usr/lib64/squid/basic_ncsa_auth. Check with ls on your system before continuing.
How do you create proxy users?
The NCSA helper reads an htpasswd style file. Create it with the first user, then add more without the -c flag, which would overwrite the file:
sudo htpasswd -c /etc/squid/passwords alice
sudo htpasswd /etc/squid/passwords bobSquid runs as an unprivileged account that must be able to read the file. That account is proxy on Debian and Ubuntu and squid on Rocky and Alma:
# Ubuntu and Debian
sudo chown root:proxy /etc/squid/passwords
# Rocky and Alma
sudo chown root:squid /etc/squid/passwords
sudo chmod 640 /etc/squid/passwordsRemove a user later with sudo htpasswd -D /etc/squid/passwords bob followed by a reload.
What should the configuration file contain?
The packaged file is thousands of lines of comments. Keep it for reference and write a compact one in its place:
sudo mv /etc/squid/squid.conf /etc/squid/squid.conf.dist
sudo nano /etc/squid/squid.confPaste this, using the helper path for your distribution:
http_port 3128
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwords
auth_param basic children 5
auth_param basic realm private proxy
auth_param basic credentialsttl 2 hours
acl authenticated proxy_auth REQUIRED
acl SSL_ports port 443
acl Safe_ports port 80 443 1025-65535
acl CONNECT method CONNECT
acl private_dst dst 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 169.254.0.0/16 fc00::/7 fe80::/10
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access deny to_localhost
http_access deny private_dst
http_access allow authenticated
http_access deny all
cache deny all
forwarded_for delete
via off
access_log daemon:/var/log/squid/access.log
coredump_dir /var/spool/squidRules are read top to bottom and the first match wins. The deny lines stop users from reaching the server itself or private networks through the proxy, and forwarded_for delete with via off keeps your client address out of request headers.
How do you check the syntax and start Squid?
Let Squid parse the file before applying it, then enable the service:
sudo squid -k parse
sudo systemctl enable --now squid
sudo systemctl reload squid
sudo ss -lntp | grep 3128A parse run that ends without FATAL or ERROR lines is good. On Rocky and Alma, SELinux already labels port 3128 for Squid; if you choose another port, add it with sudo semanage port -a -t squid_port_t -p tcp 8443. Use reload for user and rule changes: it keeps existing connections alive, whereas restart drops them.
How do you limit which addresses may connect?
Allow port 3128 only from the networks that really use the proxy. On Ubuntu and Debian with ufw:
sudo ufw allow from 203.0.113.50 to any port 3128 proto tcp
sudo ufw statusOn Rocky and Alma with firewalld:
sudo firewall-cmd --permanent --add-rich-rule="rule family=ipv4 source address=203.0.113.50/32 port port=3128 protocol=tcp accept"
sudo firewall-cmd --reloadIf your client addresses change all the time, connect over a VPN and allow the tunnel interface instead, as described in the WireGuard guide. More rule examples are in the ufw and firewalld guides.
How do you confirm authentication is enforced?
Run curl from an allowed client, first without and then with credentials:
curl -x http://198.51.100.24:3128 -sI https://example.net | head -1
curl -x http://alice:PASSWORD@198.51.100.24:3128 -sI https://example.net | head -1The first call reports 407 Proxy Authentication Required; the second shows the normal status of the site. On the server, follow the access log while you test:
sudo tail -f /var/log/squid/access.logEach line lists the client, the user name, the method and the target. A TCP_DENIED/407 entry marks an attempt without valid credentials. More curl options are covered in the curl guide.
How do browsers and tools use the proxy?
Most programs accept an HTTP proxy setting with the server, port, user and password. For command line tools, environment variables are the usual route:
export https_proxy=http://alice:PASSWORD@198.51.100.24:3128
export http_proxy=$https_proxy
curl -sI https://example.netBrowsers ask for the user name and password in a dialog the first time. Keep in mind that Basic authentication sends the credentials to the proxy in base64, not encrypted. Over a VPN or an SSH tunnel such as ssh -L 3128:127.0.0.1:3128 deploy@198.51.100.24 that is not a concern; across an open network, prefer one of those routes and point clients at 127.0.0.1:3128.
How do you maintain Squid and solve common errors?
Security updates come with normal package upgrades. Rotate logs with the bundled logrotate job and watch disk usage, because busy proxies write large access logs.
sudo apt upgrade -y # Ubuntu and Debian
sudo dnf upgrade -y # Rocky and Alma
sudo squid -k rotate
sudo journalctl -u squid -n 50 --no-pager- 407 even with the right password: the helper cannot read the password file. Check owner and mode, and the helper path.
- 403 on every site: an
http_access denyline sits above the allow line, or the target port is not inSafe_ports. - Connection refused: the firewall blocks the client or Squid failed to start; check
ssand the journal.
Watch outgoing transfer as well: every byte a client downloads through the proxy leaves the server again toward that client; usage monitoring shows the monthly total.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Squid forward proxy with authentication
Does Squid see the content of HTTPS pages?
No. With this configuration it only relays the encrypted CONNECT tunnel and logs the host name and byte count. Decrypting HTTPS would require installing your own CA on every client, which this guide does not do.
Can I give each user a different outgoing IP?
Only if the server had several addresses. Each plan has one IPv4 and one IPv6 address, so all users leave through those.
Should caching be enabled?
For a privacy or fixed-address proxy, no: most traffic is HTTPS and cannot be cached anyway. cache deny all also keeps disk usage flat.
Is a SOCKS proxy a better fit?
For apps that support SOCKS, an SSH dynamic tunnel or Shadowsocks may suit better. Squid is the natural choice when software only knows HTTP proxies.
Can I use Squid on port 80 or 443?
You can change http_port, but those ports are better left for a web server. A high port with a source allow list draws far less scanning.
More in VPN and private DNS
- WireGuard VPN server (manual setup)
- wg-easy WireGuard web UI
- WGDashboard for WireGuard
- OpenVPN server with easy-rsa
- Pritunl VPN server
- OpenConnect VPN server (ocserv)
- AdGuard Home DNS filter
- Pi-hole DNS sinkhole
- Unbound validating resolver
- Technitium DNS Server
- IPsec VPN with strongSwan
- Shadowsocks proxy server
- Authoritative DNS with BIND 9