{"id":1603,"date":"2018-12-19T00:45:21","date_gmt":"2018-12-18T21:45:21","guid":{"rendered":"http:\/\/kifarunix.com\/?p=1603"},"modified":"2024-03-11T21:43:23","modified_gmt":"2024-03-11T18:43:23","slug":"how-to-setup-squid-proxy-basic-authentication-with-username-and-password","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/how-to-setup-squid-proxy-basic-authentication-with-username-and-password\/","title":{"rendered":"Setup Squid Proxy Authentication on Ubuntu 18.04\/Fedora 29\/28\/CentOS 7"},"content":{"rendered":"\n<p>Welcome to our guide on how to setup Squid Proxy Authentication on Ubuntu 18.04\/Fedora 29\/28\/CentOS 7 with username and password.<\/p>\n\n\n\n<p>You may also want to check our previous article on <a href=\"https:\/\/kifarunix.com\/how-to-install-and-configure-squid-proxy-on-fedora-29-fedora-28-centos-7\/\" target=\"_blank\" rel=\"noopener\">how to install and configure Squid Proxy on Fedora 29\/Fedora 28\/CentOS 7<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting up Squid Proxy Authentication on Ubuntu\/Fedora\/CentOS<\/h2>\n\n\n\n<p>In order to setup Squid proxy authentication with a basic username and password, you need to make a few adjustments on the squid configuration file as follows;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Generate Squid Proxy Authentication Passwords<\/h3>\n\n\n\n<p><code>htpasswd<\/code> and <code>htdigest<\/code> are two tools that can be used to generate proxy user authentication passwords. While htpasswd encrypts the passwords and store them in a hashed format, htdigest stores the passwords in plain text hence insecure. In this guide, we are going to use htpasswd utility.<\/p>\n\n\n\n<p>In order to use htpasswd, you need to have <code>httpd\/apache2-utils<\/code> installed. To install it;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install apache2-utils<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo yum install httpd-tools<\/code><\/pre>\n\n\n\n<p>Once it is installed, run the commands below to generate the password for users to authenticate.<\/p>\n\n\n\n<pre id=\"block-9d47d27e-c23d-4366-9191-7c378c4c1b71\" class=\"wp-block-code\"><code><strong>htpasswd -c \/etc\/squid\/.squid_users amos<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>New password: ENTER PASS\nRe-type new password: ENTER PASS\nAdding password for user amos<\/code><\/pre>\n\n\n\n<p>This creates a password for user amos and store it under <code>\/etc\/squid\/.squid_users<\/code>.<\/p>\n\n\n\n<p>To add more users, you need to remove option <strong>-c<\/strong> from the htpasswd command for example;<\/p>\n\n\n\n<pre id=\"block-cd9ed416-c92d-4057-b8b7-0a0dc44e6b04\" class=\"wp-block-code\"><code>htpasswd \/etc\/squid\/.squid_users john<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>New password: \nRe-type new password: \nAdding password for user john<\/code><\/pre>\n\n\n\n<p>When you check the password file, there are now two users with their encrypted passwords;<\/p>\n\n\n\n<pre id=\"block-820809da-d6ba-449f-8666-78a32fea1d62\" class=\"wp-block-code\"><code><strong>less \/etc\/squid\/.squid_users<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>amos:$apr1$IyfTZICg$2fPImX5o14XC2KPF1kZWv\/\njohn:$apr1$5o0XKeto$m6c5B5KK5ZAK\/7A\/VIgYB\/<\/code><\/pre>\n\n\n\n<p>The squid user should be able to read this file. Therefore run the command below to set proper permissions;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chown squid \/etc\/squid\/.squid_users<\/code><\/pre>\n\n\n\n<p>Verify that the usernames and passwords provide works fine with Squid proxy.<\/p>\n\n\n\n<p>For every correct entry, you should see <code>OK<\/code> displayed as shown below;<\/p>\n\n\n\n<pre id=\"block-3dda853b-88f2-462c-a425-b2758a0d9e03\" class=\"wp-block-code\"><code>\/usr\/lib64\/squid\/basic_ncsa_auth \/etc\/squid\/.squid_users <\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>amos password\nOK<\/strong>\n<strong>john password\nOK<\/strong><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configure Squid Proxy Authentication<\/h3>\n\n\n\n<p>Since all seems fine, proceed to setup squid proxy basic authentication.<\/p>\n\n\n\n<p>Open the squid configuration file for editing and add the following lines.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>auth_param basic program \/usr\/lib64\/squid\/basic_ncsa_auth \/etc\/squid\/.squid_users\nauth_param basic children 5\nauth_param basic realm Proxy Authentication Required\nauth_param basic credentialsttl 2 hours\nauth_param basic casesensitive off\n\nacl auth_users proxy_auth amos john\nhttp_access allow auth_users<\/code><\/pre>\n\n\n\n<p>As a brief overview of the lines set above;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The first line tells the Squid to use the <code>basic_ncsa_auth<\/code> helper program and find the usernames and password in <code>\/etc\/squid\/.squid_users<\/code> file.<\/li>\n\n\n\n<li>The line <code>auth_param basic children 5<\/code> specifies the maximum number of squid authenticator processes to spawn.<\/li>\n\n\n\n<li><code>auth_param basic realm<\/code> specifies the protection scope which is to be reported to the client for the authentication scheme.<\/li>\n\n\n\n<li><code>auth_param basic credentialsttl 2 hours<\/code> specifies how long squid assumes an externally validated username:password pair is valid for<\/li>\n\n\n\n<li><code>auth_param basic casesensitive off<\/code> specifies if usernames are case sensitive.<\/li>\n\n\n\n<li><code>acl auth_users proxy_auth amos john<\/code> defines Squid authentication ACL for users that are allowed to authenticate.<\/li>\n<\/ul>\n\n\n\n<p>Once you are done with configurations, save the file and restart squid.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl restart squid<\/code><\/pre>\n\n\n\n<p>Configure your client to use authenticate vai squid proxy server as described in our <a href=\"https:\/\/kifarunix.com\/how-to-install-and-configure-squid-proxy-on-fedora-29-fedora-28-centos-7\/\" target=\"_blank\" rel=\"noopener\">previous<\/a> article.<\/p>\n\n\n\n<p>From the client side, if you try to access the internet via browser, you will be prompted to authenticate. See screenshot below;<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"783\" height=\"353\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/10\/squid-proxy-authentication.png\" alt=\"Setup Squid Proxy Authentication on Ubuntu 18.04\/Fedora 29\/28\/CentOS 7\" class=\"wp-image-10749\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/10\/squid-proxy-authentication.png?v=1634672507 783w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/10\/squid-proxy-authentication-768x346.png?v=1634672507 768w\" sizes=\"(max-width: 783px) 100vw, 783px\" \/><\/figure><\/div>\n\n\n<p>When you authenticate properly, you will be able to access the internet on browser.<\/p>\n\n\n\n<p>If you try to download a file using wget, you will be prompted to authenticate;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget google.com<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>--2018-12-19 00:38:21--  http:\/\/google.com\/\n<strong>Connecting to 192.168.43.69:3128<\/strong>... connected.\nProxy request sent, awaiting response... 407 Proxy Authentication Required\n2018-12-19 00:38:21 ERROR 407: <strong>Proxy Authentication Required<\/strong>.<\/code><\/pre>\n\n\n\n<p>Hence;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget <strong>--proxy-user=amos --proxy-password=password<\/strong> google.com<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>--2018-12-19 00:39:36--  http:\/\/google.com\/\nConnecting to 192.168.43.69:3128... connected.\nProxy request sent, awaiting response... 301 Moved Permanently\nLocation: http:\/\/www.google.com\/ &#91;following]\n--2018-12-19 00:39:37--  http:\/\/www.google.com\/\nReusing existing connection to 192.168.43.69:3128.\nProxy request sent, awaiting response... 200 OK\nLength: unspecified &#91;text\/html]\nSaving to: \u2018index.html.8\u2019\n\nindex.html.8            &#91; &lt;=&gt;                ]  11.72K  --.-KB\/s    in 0.1s    \n\n2018-12-19 00:39:38 (97.6 KB\/s) - \u2018index.html.8\u2019 saved &#91;12001]<\/code><\/pre>\n\n\n\n<p>Well, there you go. You have successfully setup Squid proxy authentication on Ubuntu 18.04\/Fedora29\/28\/CentOS 7 with username and password. In our next tutorial, we are going to learn how to integrate Squid proxy with LDAP servers for centralized authentication. Thank you for passing by. We hope this was informative.<\/p>\n\n\n\n<p>Hey, want to learn how to set system wide proxy settings on Ubuntu 18.04? You can catch that by following the link below;<\/p>\n\n\n\n<p><a title=\"How to Set System Wide Proxy in Ubuntu 18.04\" href=\"https:\/\/kifarunix.com\/how-to-set-system-wide-proxy-in-ubuntu-18-04\/\" target=\"_blank\" rel=\"bookmark noopener\">How to Set System Wide Proxy in Ubuntu 18.04<\/a><\/p>\n\n\n\n<p>Other tutorials<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/configure-squid-proxy-openldap-authentication-on-pfsense\/\" target=\"_blank\" rel=\"noreferrer noopener\">Configure Squid Proxy OpenLDAP Authentication on pfSense<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-and-setup-squid-proxy-on-pfsense\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install and Setup Squid Proxy on pfSense<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to our guide on how to setup Squid Proxy Authentication on Ubuntu 18.04\/Fedora 29\/28\/CentOS 7 with username and password. You may also want to<\/p>\n","protected":false},"author":1,"featured_media":10750,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[34,121,250],"tags":[1681,4205,277,1761,4206],"class_list":["post-1603","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-security","category-howtos","category-proxy","tag-authentication","tag-setup-squid-proxy-authentication","tag-squid-proxy","tag-squid-proxy-authentication","tag-squid-proxy-authentication-on-ubuntu-18-04-fedora-29-28-centos-7","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1603"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=1603"}],"version-history":[{"count":7,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1603\/revisions"}],"predecessor-version":[{"id":21076,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1603\/revisions\/21076"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/10750"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=1603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=1603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=1603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}