How to set up a private Squid proxy with password authentication
Install Squid (the most widely used open-source forward proxy) on a server you control, create users with htpasswd, tell Squid to allow only logged-in users from your own IP addresses, and firewall port 3128 to those addresses. Never run an open proxy that anyone can use.
Who is this for?
- IT leads and adminsYou’ll use it to run a private, password-protected Squid proxy on your own server, limited to your own IP addresses.
- Small teams that need one fixed office IP addressYou’ll use it to give a partner one address to put on an allow-list, or test how your site looks from another region.
What is a private proxy good for?
A forward proxy is a server your browser or app sends web requests through, so websites see the proxy's address instead of yours. Legitimate uses for a small team: testing how your own site looks from another region, giving the team one fixed office IP address that a partner can put on an allow-list, and sending team browsing through one exit you can audit.
A proxy doesn't encrypt your traffic on the way to it. If people connect from outside your office, reach the proxy over a WireGuard VPN (see the VPN guide) so passwords don't cross the internet in the clear.
Why not buy residential proxies instead?
Don't. "Residential proxies" route your traffic through other people's home internet connections, and many of those connections come from devices whose owners never knowingly agreed, including devices taken over by malware. U.S. law enforcement has taken down botnets that were sold this way. Paying for one can put your traffic, and your name, behind someone else's hijacked device.
What do you need before you start?
A server you own or rent running Ubuntu 24.04 LTS, SSH access with sudo, and the public IP addresses of the places your team will connect from. Placeholders are written like <OFFICE_IP>: replace the whole thing, brackets included.
How do you set it up, step by step?
Install Squid and the password tool
Squid comes from Ubuntu's own repository; apache2-utils provides htpasswd, which makes the password file.
sudo apt update sudo apt install -y squid apache2-utilsCreate a username and password for each person
The first command creates the file (-c) and asks for a password. Leave -c off when adding more people, or it overwrites the file. Then let only Squid's user read it.
sudo htpasswd -c /etc/squid/passwords <USERNAME> sudo htpasswd /etc/squid/passwords <ANOTHER_USERNAME> sudo chown proxy:proxy /etc/squid/passwords sudo chmod 640 /etc/squid/passwordsRequire a login and allow only your own IP addresses
Ubuntu's squid.conf reads extra settings from /etc/squid/conf.d/ before its own allow and deny rules. The block below writes a file there; replace <OFFICE_IP> first. Order matters: Squid uses the first http_access line that matches, so everyone outside your IPs is denied before anyone is asked for a password.
sudo tee /etc/squid/conf.d/private-proxy.conf > /dev/null <<'EOF' auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwords auth_param basic realm Private proxy auth_param basic credentialsttl 2 hours acl our_ips src <OFFICE_IP>/32 acl logged_in proxy_auth REQUIRED http_access deny !our_ips http_access allow logged_in http_access deny all EOFCheck the configuration and restart Squid
squid -k parse reports mistakes without changing anything. Fix any error it prints before restarting.
sudo squid -k parse sudo systemctl restart squid sudo systemctl enable squidFirewall the proxy port to your own IPs
Squid listens on TCP port 3128. Open it only to your own addresses, never to everyone. If your team connects over WireGuard, allow the VPN subnet instead of office IPs.
sudo ufw allow OpenSSH sudo ufw allow from <OFFICE_IP> to any port 3128 proto tcp sudo ufw enable sudo ufw statusTest it
From an allowed computer, the first command should ask for the password and then succeed; the second, with no login, should fail with 407 Proxy Authentication Required. Typing the password at the prompt keeps it out of your shell history.
curl -I -x http://<SERVER_PUBLIC_IP>:3128 --proxy-user <USERNAME> https://example.com curl -I -x http://<SERVER_PUBLIC_IP>:3128 https://example.comDecide how long to keep logs
Squid records each request in /var/log/squid/access.log. Keep only what you need for security reviews, tell your team the proxy is logged, and set how often logs rotate and how many old files are kept in /etc/logrotate.d/squid.
sudo tail -n 20 /var/log/squid/access.log sudo nano /etc/logrotate.d/squidKeep it patched and remove people who leave
Turn on automatic security updates. When someone leaves, delete their line from the password file and reload Squid.
sudo apt install -y unattended-upgrades sudo dpkg-reconfigure -plow unattended-upgrades sudo htpasswd -D /etc/squid/passwords <USERNAME> sudo systemctl reload squid
Never run an open proxy
A proxy that anyone on the internet can use is found by scanners quickly and used for spam, fraud and attacks, all from your server's address. Keep both locks on: the password and the firewall. Run this only on a server you own, and follow your hosting provider's terms of service and the law where you and the sites you visit are.
Questions
- What port does Squid use?
- TCP port 3128 by default (the http_port setting). Firewall it so only your own IP addresses or your VPN can reach it.
- Is Squid's basic authentication encrypted?
- No. Basic authentication sends the username and password encoded, not encrypted, to the proxy. Reach the proxy over a VPN or only from your own network.
- Are residential proxies safe to use?
- Not recommended. Many route traffic through home devices whose owners never knowingly agreed, including devices taken over by malware. Run your own proxy instead.
- How do I remove a user from Squid?
- Run sudo htpasswd -D /etc/squid/passwords <USERNAME>, then sudo systemctl reload squid.
Related
- Security hub for small HR and remote teams: every guide, tool and service in one place
- WireGuard VPN on your own server
- VPN vs. proxy for a small business
- WireGuard config generator
- AI coding-assistant scanner
Sources
This page is general information, not legal advice. Rules on monitoring, data retention and network use differ by country and state; check yours with a lawyer.
For your own systems and lawful use only. Don't use these guides or tools on servers, networks or accounts you don't own or aren't authorized to run.
Want us to set it up for you? See Secure Remote Access for HR Systems.