360 Secure SkillHub
360 安全技能中心

Htpasswd

通过 Bash 脚本封装 openssl 实现 htpasswd 文件管理:创建密码文件、增删用户、列出用户及哈希类型、校验密码,支持 apr1、sha256、sha512 算法,文件以 640 权限创建,无外部依赖或 API 密钥。

bytesagain-lab
bytesagain-lab
热度 85.96
最近更新 2026-05-17 14:37:39
分类:安全依赖:代码执行 / 读写文件应用场景:DevOps / 自动化脚本 / 工作流

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add htpasswd
Metadata
name
HtPasswd
description
Generate htpasswd entries for Apache/Nginx basic auth password management. Use when creating credentials, managing password files, or verifying users.
version
3.0.0
author
BytesAgain
homepage
https://bytesagain.com
source
https://github.com/bytesagain/ai-skills
tags
["htpasswd","password","auth","apache","nginx","security"]
categories
["Developer Tools","Utility"]

HtPasswd

A real htpasswd file manager for Apache/Nginx HTTP basic authentication. Create password files, add/remove users, verify passwords, and list users. Supports apr1 (Apache MD5), SHA-256, and SHA-512 hash algorithms via openssl.

Commands

Command Description
htpasswd create <file> <user> <password> Create a new htpasswd file with the first user (fails if file exists)
htpasswd add <file> <user> <password> Add a user to an existing file (or update password if user exists)
htpasswd delete <file> <user> Remove a user from the htpasswd file
htpasswd verify <file> <user> <password> Verify a user's password (supports apr1, sha256, sha512, sha1, crypt)
htpasswd list <file> List all users with their hash algorithm type
htpasswd version Show version
htpasswd help Show available commands and usage

Configuration

Variable Default Description
HTPASSWD_ALGO apr1 Hash algorithm: apr1, sha256, or sha512

Requirements

  • Bash 4+ (set -euo pipefail)
  • openssl — for password hashing and verification
  • grep, sed — standard text utilities
  • No external dependencies or API keys

When to Use

  1. Setting up basic auth — htpasswd create /etc/nginx/.htpasswd admin secret to create a new file
  2. Managing users — htpasswd add to add users, htpasswd delete to remove them
  3. Password verification — htpasswd verify to check if a password is correct
  4. Security audits — htpasswd list shows all users and their hash types
  5. Stronger hashing — Set HTPASSWD_ALGO=sha512 for SHA-512 instead of default apr1

Examples

# Create a new htpasswd file
htpasswd create /etc/nginx/.htpasswd admin MySecretPass

# Add another user
htpasswd add /etc/nginx/.htpasswd editor AnotherPass

# Use SHA-512 for stronger hashing
HTPASSWD_ALGO=sha512 htpasswd add /etc/nginx/.htpasswd secure_user StrongPass

# List all users
htpasswd list /etc/nginx/.htpasswd

# Verify a password
htpasswd verify /etc/nginx/.htpasswd admin MySecretPass

# Delete a user
htpasswd delete /etc/nginx/.htpasswd editor

Example Output

$ htpasswd create /tmp/.htpasswd admin secret123
┌──────────────────────────────────────────────────┐
│  htpasswd File Created                           │
├──────────────────────────────────────────────────┤
│  File:     /tmp/.htpasswd                         │
│  User:     admin                                  │
│  Algo:     apr1                                   │
│  Perms:    640 (owner rw, group r)                │
├──────────────────────────────────────────────────┤
│  ✅ File created with 1 user                     │
└──────────────────────────────────────────────────┘

$ htpasswd list /tmp/.htpasswd
┌──────────────────────────────────────────────────┐
│  htpasswd Users                                  │
├──────────────────────────────────────────────────┤
│  File:  /tmp/.htpasswd                            │
│  Users: 2                                         │
├──────────────────────────────────────────────────┤
│   1. admin                [apr1 (MD5)      ]      │
│   2. editor               [sha512          ]      │
└──────────────────────────────────────────────────┘

$ htpasswd verify /tmp/.htpasswd admin secret123
┌──────────────────────────────────────────────────┐
│  Password Verification                           │
├──────────────────────────────────────────────────┤
│  File:     /tmp/.htpasswd                         │
│  User:     admin                                  │
│  Result:   ✅ Password CORRECT                   │
└──────────────────────────────────────────────────┘

Security Notes

  • Files are created with 640 permissions (owner read/write, group read)
  • Default algorithm is apr1 (Apache MD5) — widely compatible
  • Use HTPASSWD_ALGO=sha512 for stronger hashing on modern systems
  • Usernames cannot contain : or whitespace characters
  • Existing users get their password replaced when using add

Powered by BytesAgain | bytesagain.com | hello@bytesagain.com