Skip to content

Instantly share code, notes, and snippets.

@cdodd
Last active June 17, 2022 15:08
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
  • Save cdodd/8886180 to your computer and use it in GitHub Desktop.
Save cdodd/8886180 to your computer and use it in GitHub Desktop.
Install a basic squid proxy with authentication on Centos 6 x64. Just modify the variables at the top and run the script on a clean system.
#!/bin/sh
PROXY_USER=user
PROXY_PASS=password
PROXY_PORT=3128
# Clear the repository index caches
yum clean all
# Update the operating system
yum update -y
# Install httpd-tools to get htpasswd
yum install httpd-tools -y
# Install squid
yum install squid -y
# Create the htpasswd file
htpasswd -c -b /etc/squid/passwords $PROXY_USER $PROXY_PASS
# Backup the original squid config
cp /etc/squid/squid.conf /etc/squid/squid.conf.bak
# Set up the squid config
cat << EOF > /etc/squid/squid.conf
auth_param basic program /usr/lib64/squid/ncsa_auth /etc/squid/passwords
auth_param basic realm proxy
acl authenticated proxy_auth REQUIRED
http_access allow authenticated
forwarded_for delete
http_port 0.0.0.0:$PROXY_PORT
EOF
# Set squid to start on boot
chkconfig squid on
# Start squid
/etc/init.d/squid start
# Set up the iptables config
cat << EOF > /etc/sysconfig/iptables
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
#######################################################
# BEGIN CUSTOM RULES
#######################################################
# Allow SSH from anywhere
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
# Allow squid access from anywhere
-A INPUT -m state --state NEW -m tcp -p tcp --dport $PROXY_PORT -j ACCEPT
#######################################################
# END CUSTOM RULES
#######################################################
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
EOF
# Restart iptables
/etc/init.d/iptables restart
@SoWhat-lv
Copy link

finally a working solution for Squid + Authentication + Centos 6.5
Thank you!

@ydaniels
Copy link

nice one man

@jolinx
Copy link

jolinx commented Nov 4, 2015

forked,Thanks.
another compile install method: http://my.oschina.net/u/1162688/blog/415837

@JeremyTayl0r
Copy link

@yifeikong
Copy link

why do I have to use iptables, I mean squid just redirect traffic in http level, how is iptables involved?

Copy link

ghost commented Aug 5, 2017

@yifeikong likely to allow ingress connections to 3128

Copy link

ghost commented Aug 5, 2017

This states that this is for Centos 6 x64. Is it only for 6.8?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment