Squid设置用户名密码

在ubutnu上设置squid代理认证
为了在Ubuntu上设置Squid代理身份验证,您需要对Squid配置文件进行以下一些调整:
生成Squid代理身份验证密码
htpasswd是两种可用于生成代理用户身份验证密码的工具。虽然 htpasswd 加密密码并以混杂格式存储密码,但 htdigest 将密码存储在纯文本中,因此不安全。在此指南中,我们将使用 htpasswd 实用程序。htdigest
为了使用htpasswd,您需要安装。安装它:httpd/apache2-utils

sudo apt-get install apache2-utils
sudo yum install httpd-tools

安装后,运行下面的命令以生成密码供用户验证。

htpasswd -c /etc/squid/.squid_users amos
New password: 
Re-type new password: 
Adding password for user amos

这为用户amos创建一个密码,并将其存储在。/etc/squid/.squid_users

要添加更多用户,您需要从htpasswd命令中删除选项-c:

htpasswd /etc/squid/.squid_users john
New password: 
Re-type new password: 
Adding password for user john

当您检查密码文件时,现在有两个用户使用加密密码:

less /etc/squid/.squid_users
amos:$apr1$IyfTZICg$2fPImX5o14XC2KPF1kZWv/
john:$apr1$5o0XKeto$m6c5B5KK5ZAK/7A/VIgYB/

squid用户应该能够阅读此文件。因此,运行下面的命令以设置适当的权限:

chown squid /etc/squid/.squid_users

验证用户名和密码是否适用于squid代理。对于每一个正确的条目,您应该看到如下所示显示:OK

/usr/lib64/squid/basic_ncsa_auth /etc/squid/.squid_users 
amos password
OK
john password
OK

配置Squid代理身份验证
由于一切似乎都很好,继续设置Squid代理基本身份验证。打开Squid配置文件进行编辑并添加以下行。

auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/.squid_users
auth_param basic children 5
auth_param basic realm Proxy Authentication Required
auth_param basic credentialsttl 2 hours
auth_param basic casesensitive off

acl auth_users proxy_auth amos john
http_access allow auth_users

作为上面所述行的简要概述:

  • 第一行告诉Squid使用帮手程序,并在文件中查找用户名和密码。basic_ncsa_auth/etc/squid/.squid_users
  • 该线指定了生成Squid身份验证器过程的最大数量。auth_param basic children 5
  • auth_param basic realm指定要向客户报告身份验证方案的保护范围。
  • auth_param basic credentialsttl 2 hours指定Squid假定外部验证的用户名有多长:密码对适用于
  • auth_param basic casesensitive off指定用户名是否对案例敏感。
  • acl auth_users proxy_auth amos john为允许身份验证的用户定义Squid身份验证 ACL。
    完成配置后,保存文件并重新启动Squid。
systemctl restart squid

配置您的客户端,以使用我们上一篇文章中描述的验证 vai squid代理服务器。

从客户端看,如果您尝试通过浏览器访问互联网,将提示您进行身份验证。请参阅下面的屏幕截图:
在这里插入图片描述
当您正确身份验证时,您将能够在浏览器上访问互联网。

如果您尝试使用wget下载文件,将提示您进行身份验证:

wget google.com               
--2018-12-19 00:38:21--  http://google.com/
Connecting to 192.168.43.69:3128... connected.
Proxy request sent, awaiting response... 407 Proxy Authentication Required
2018-12-19 00:38:21 ERROR 407: Proxy Authentication Required.

因此:

wget --proxy-user=amos --proxy-password=password google.com
--2018-12-19 00:39:36--  http://google.com/
Connecting to 192.168.43.69:3128... connected.
Proxy request sent, awaiting response... 301 Moved Permanently
Location: http://www.google.com/ [following]
--2018-12-19 00:39:37--  http://www.google.com/
Reusing existing connection to 192.168.43.69:3128.
Proxy request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.html.8’

index.html.8            [ <=>                ]  11.72K  --.-KB/s    in 0.1s    

2018-12-19 00:39:38 (97.6 KB/s) - ‘index.html.8’ saved [12001]

好了,你去吧您已经成功地在Ubuntu上设置了Squid代理身份验证,并带有用户名和密码。

posted @ 2021-03-08 15:05  避凉闲庭  阅读(2494)  评论(0编辑  收藏  举报