Loading... # 引言 对于一些私有站点,不希望别人轻易访问的,可以使用这个简单的认证模块 ![image.png](https://www.zunmx.top/usr/uploads/2024/03/1700060995.png) # 使用方法 ## 生成密钥文件 htpasswd -c -m 路径 用户名 如:`htpasswd -c -m /etc/nginx/passwd administrator` 如果首次使用,要加上`-c`,如果后续想添加别的用户,就不要再`-c`了 `-m` 属性是md5,如果觉得不够安全,可以参考下面的文档。 附上说明文档: > Usage: > htpasswd [-cimBdpsDv] [-C cost] passwordfile username > htpasswd -b[cmBdpsDv] [-C cost] passwordfile username password > -c Create a new file. 新建一个新文件 > -n Don't update file; display results on stdout. > -b Use the password from the command line rather than prompting for it. > -i Read password from stdin without verification (for script usage). > -m Force MD5 encryption of the password (default). > -2 Force SHA-256 crypt() hash of the password (very secure). > -5 Force SHA-512 crypt() hash of the password (very secure). > -B Force bcrypt encryption of the password (very secure). > -C Set the computing time used for the bcrypt algorithm > (higher is more secure but slower, default: 5, valid: 4 to 17). > -r Set the number of rounds used for the SHA-256, SHA-512 algorithms > (higher is more secure but slower, default: 5000). > -d Force CRYPT encryption of the password (8 chars max, insecure). > -s Force SHA-1 encryption of the password (insecure). > -p Do not encrypt the password (plaintext, insecure). > -D Delete the specified user. > -v Verify password for the specified user. > On other systems than Windows and NetWare the '-p' flag will probably not work. > The SHA-1 algorithm does not use a salt and is less secure than the MD5 algorithm. ## nginx 配置 在server节中配置以下: `need login` --> 提示信息 `/etc/nginx/password` --> 认证文件路径 ```properties auth_basic "need login"; auth_basic_user_file /etc/nginx/password; ``` ## apache-httpd 如果需要配置apache-httpd的基本身份认证,可参阅往期文章。 <div class="preview"> <div class="post-inser post box-shadow-wrap-normal"> <a href="https://www.zunmx.top/archives/296/" target="_blank" class="post_inser_a no-external-link no-underline-link"> <div class="inner-image bg" style="background-image: url(https://www.zunmx.top/usr/uploads/2021/05/4260055704.png);background-size: cover;"></div> <div class="inner-content" > <p class="inser-title">Apache Httpd 添加授权认证</p> <div class="inster-summary text-muted"> 引言因为我的电脑通过ApacheHttpd搭建了一个Php的服务器,作为日常使用的NAS以及文件服务,还有一些靶场... </div> </div> </a> <!-- .inner-content #####--> </div> <!-- .post-inser ####--> </div> © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏