squid代理添加认证

squid 使用 NCSA 样式的密码文件来验证用户身份

squid安装

squid认证

对于基于 Debian/Ubuntu 的系统:

sudo apt-get update
sudo apt-get install squid

对于基于 RedHat/CentOS 的系统:

sudo yum install squid

在Alpine Linux上,你可以使用apk包管理器,如下命令:

sudo apk add squid

配置文件地址:/etc/squid/squid.conf

密码文件

安装htpasswd

对于基于 Debian/Ubuntu 的系统:

sudo apt-get update
sudo apt-get install apache2-utils

对于基于 RedHat/CentOS 的系统:

sudo yum install httpd-tools

创建密码文件同时添加一个用户

htpasswd -c -bm /etc/squid/passwords username password

-c 此选项告诉 htpasswd 创建新的密码文件。如果指定的文件已经存在,那么 -c 选项会导致 htpasswd 在没有用户明确确认的情况下拒绝覆盖现有文件。如果没有指定 -c,那么 htpasswd 将会修改指定的文件,或者如果文件不存在则创建文件。需要注意的是,-c 选项不能和 -n 选项同时使用。

-b 允许从命令行中提供密码。这是不安全的,因为 UNIX 操作系统提供了各种方法可以查看运行的命令和对应的参数,这意味着你的密码可能会被其他用户看到。如果不使用 -b,那么 htpasswd 会提供安全的方式来让你输入密码。

-m 使用 MD5 算法进行加密。这是 Apache 服务器 v2.4.3 起由 default 提供的加密方式。

添加用户

htpasswd -nbm /etc/squid/passwords username password

删除用户

htpasswd -D -nbm /etc/squid/passwords username password

squid配置文件

squid.conf增加如下内容:

auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwords
auth_param basic children 10 startup=5 idle=2
auth_param basic credentialsttl 2 hours

acl auth proxy_auth REQUIRED

http_access deny !auth
http_access allow auth
http_access deny all

注意上面http_access要加在http_access allow all之前

启动

squid

若报错
2023/11/02 11:31:45| ERROR: Authentication helper program /usr/lib/squid/basic_ncsa_auth: (2) No such file or directory
FATAL: Authentication helper program /usr/lib/squid/basic_ncsa_auth: (2) No such file or directory

解决:
[root@ba8c816f41b4 squid]# find / -name basic_ncsa_auth 2>/dev/null
/usr/lib64/squid/basic_ncsa_auth

找到真正的basic_ncsa_auth地址替换squid配置文件中的auth_param basic program参数地址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值