{
    "mode": "man",
    "parameter": "htpasswd",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/htpasswd/1/json",
    "generated": "2026-06-03T01:44:33Z",
    "synopsis": "htpasswd  [ -c ] [ -i ] [ -m | -B | -d | -s | -p ] [ -C cost ] [ -D ] [ -v ] passwdfile user‐\nname\nhtpasswd -b [ -c ] [ -m | -B | -d | -s | -p ] [ -C cost ] [ -D ] [ -v ]  passwdfile  username\npassword\nhtpasswd -n [ -i ] [ -m | -B | -d | -s | -p ] [ -C cost ] username\nhtpasswd -nb [ -m | -B | -d | -s | -p ] [ -C cost ] username password",
    "sections": {
        "NAME": {
            "content": "htpasswd - Manage user files for basic authentication\n\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "htpasswd  [ -c ] [ -i ] [ -m | -B | -d | -s | -p ] [ -C cost ] [ -D ] [ -v ] passwdfile user‐\nname\n\n\nhtpasswd -b [ -c ] [ -m | -B | -d | -s | -p ] [ -C cost ] [ -D ] [ -v ]  passwdfile  username\npassword\n\n\nhtpasswd -n [ -i ] [ -m | -B | -d | -s | -p ] [ -C cost ] username\n\n\nhtpasswd -nb [ -m | -B | -d | -s | -p ] [ -C cost ] username password\n\n\n",
            "subsections": []
        },
        "SUMMARY": {
            "content": "htpasswd is used to create and update the flat-files used to store usernames and password for\nbasic authentication of HTTP users. If htpasswd cannot access a file, such as not being  able\nto  write to the output file or not being able to read the file in order to update it, it re‐\nturns an error status and makes no changes.\n\n\nResources available from the Apache HTTP server can be restricted to just the users listed in\nthe files created by htpasswd. This program can only manage usernames and passwords stored in\na flat-file. It can encrypt and display password information for use in other types  of  data\nstores, though. To use a DBM database see dbmmanage or htdbm.\n\n\nhtpasswd  encrypts passwords using either bcrypt, a version of MD5 modified for Apache, SHA1,\nor the system's crypt() routine. Files managed by htpasswd may contain a mixture of different\nencoding  types  of  passwords;  some user records may have bcrypt or MD5-encrypted passwords\nwhile others in the same file may have passwords encrypted with crypt().\n\n\nThis manual page only lists the command line arguments. For details of the directives  neces‐\nsary  to  configure  user authentication in httpd see the Apache manual, which is part of the\nApache distribution or can be found at http://httpd.apache.org/.\n\n\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "-b",
                    "content": "it.  This option should be used with extreme care, since the password is clearly visi‐‐\nble on the command line. For script use see the -i  option.  Available  in  2.4.4  and\nlater.\n",
                    "flag": "-b"
                },
                {
                    "name": "-i",
                    "content": "",
                    "flag": "-i"
                },
                {
                    "name": "-c",
                    "content": "This option cannot be combined with the -n option.\n",
                    "flag": "-c"
                },
                {
                    "name": "-n",
                    "content": "generating  password  records  acceptable  to  Apache  for  inclusion in non-text data\nstores. This option changes the syntax of the command line, since the passwdfile argu‐\nment (usually the first one) is omitted. It cannot be combined with the -c option.\n",
                    "flag": "-n"
                },
                {
                    "name": "-m",
                    "content": "",
                    "flag": "-m"
                },
                {
                    "name": "-B",
                    "content": "",
                    "flag": "-B"
                },
                {
                    "name": "-C -B",
                    "content": "puting time used for the bcrypt algorithm (higher is more secure but slower,  default:\n5, valid: 4 to 17).\n",
                    "flag": "-B"
                },
                {
                    "name": "-d",
                    "content": "Windows and Netware. This algorithm limits the password length to 8  characters.  This\nalgorithm  is insecure by today's standards. It used to be the default algorithm until\nversion 2.2.17.\n",
                    "flag": "-d"
                },
                {
                    "name": "-s",
                    "content": "the  LDAP  Directory  Interchange Format (ldif). This algorithm is insecure by today's\nstandards.\n",
                    "flag": "-s"
                },
                {
                    "name": "-p",
                    "content": "httpd daemon will only accept plain text passwords on Windows and Netware.\n",
                    "flag": "-p"
                },
                {
                    "name": "-D",
                    "content": "deleted.\n",
                    "flag": "-D"
                },
                {
                    "name": "-v",
                    "content": "stored in the specified htpasswd file. Available in 2.4.5 and later.\n\npasswdfile\nName  of  the file to contain the user name and password. If -c is given, this file is\ncreated if it does not already exist, or rewritten and truncated if it does exist.\n\nusername\nThe username to create or update in passwdfile. If username does  not  exist  in  this\nfile, an entry is added. If it does exist, the password is changed.\n\npassword\nThe  plaintext  password to be encrypted and stored in the file. Only used with the -b\nflag.\n\n",
                    "flag": "-v"
                }
            ]
        },
        "EXIT STATUS": {
            "content": "htpasswd returns a zero status (\"true\") if the username and password have  been  successfully\nadded  or updated in the passwdfile. htpasswd returns 1 if it encounters some problem access‐\ning files, 2 if there was a syntax problem with the command line, 3 if the password  was  en‐\ntered  interactively  and  the verification entry didn't match, 4 if its operation was inter‐\nrupted, 5 if a value is too long (username, filename, password, or final computed record),  6\nif the username contains illegal characters (see the Restrictions section), and 7 if the file\nis not a valid password file.\n\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "htpasswd /usr/local/etc/apache/.htpasswd-users jsmith\n\n\n\nAdds or modifies the password for user jsmith. The user is prompted  for  the  password.  The\npassword  will be encrypted using the modified Apache MD5 algorithm. If the file does not ex‐\nist, htpasswd will do nothing except return an error.\n\n\nhtpasswd -c /home/doe/publichtml/.htpasswd jane\n\n\n\nCreates a new file and stores a record in it for user jane. The  user  is  prompted  for  the\npassword.  If the file exists and cannot be read, or cannot be written, it is not altered and\nhtpasswd will display a message and return an error status.\n\n\nhtpasswd -db /usr/web/.htpasswd-all jones Pwd4Steve\n\n\n\nEncrypts the password from the command line (Pwd4Steve)  using  the  crypt()  algorithm,  and\nstores it in the specified file.\n\n",
            "subsections": []
        },
        "SECURITY CONSIDERATIONS": {
            "content": "Web  password  files  such as those managed by htpasswd should not be within the Web server's\nURI space -- that is, they should not be fetchable with a browser.\n\n\nThis program is not safe as a setuid executable. Do not make it setuid.\n\n\nThe use of the -b option is discouraged, since when it is used the unencrypted  password  ap‐\npears on the command line.\n\n\nWhen  using  the crypt() algorithm, note that only the first 8 characters of the password are\nused to form the password. If the supplied password is longer, the extra characters  will  be\nsilently discarded.\n\n\nThe  SHA  encryption format does not use salting: for a given password, there is only one en‐\ncrypted representation. The crypt() and MD5 formats permute the representation by  prepending\na random salt string, to make dictionary attacks against the passwords more difficult.\n\n\nThe SHA and crypt() formats are insecure by today's standards.\n\n",
            "subsections": []
        },
        "RESTRICTIONS": {
            "content": "On  the  Windows  platform, passwords encrypted with htpasswd are limited to no more than 255\ncharacters in length. Longer passwords will be truncated to 255 characters.\n\n\nThe MD5 algorithm used by htpasswd is specific to the Apache  software;  passwords  encrypted\nusing it will not be usable with other Web servers.\n\n\nUsernames are limited to 255 bytes and may not include the character :.\n\n\nThe cost of computing a bcrypt password hash value increases with the number of rounds speci‐\nfied by the -C option. The apr-util library enforces a maximum number of rounds of 17 in ver‐\nsion 1.6.0 and later.\n\n\n\n\nApache HTTP Server                           2019-08-09                                  HTPASSWD(1)",
            "subsections": []
        }
    },
    "summary": "htpasswd - Manage user files for basic authentication",
    "flags": [
        {
            "flag": "-b",
            "long": null,
            "arg": null,
            "description": "it. This option should be used with extreme care, since the password is clearly visi‐‐ ble on the command line. For script use see the -i option. Available in 2.4.4 and later."
        },
        {
            "flag": "-i",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "-c",
            "long": null,
            "arg": null,
            "description": "This option cannot be combined with the -n option."
        },
        {
            "flag": "-n",
            "long": null,
            "arg": null,
            "description": "generating password records acceptable to Apache for inclusion in non-text data stores. This option changes the syntax of the command line, since the passwdfile argu‐ ment (usually the first one) is omitted. It cannot be combined with the -c option."
        },
        {
            "flag": "-m",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "-B",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "-B",
            "long": null,
            "arg": null,
            "description": "puting time used for the bcrypt algorithm (higher is more secure but slower, default: 5, valid: 4 to 17)."
        },
        {
            "flag": "-d",
            "long": null,
            "arg": null,
            "description": "Windows and Netware. This algorithm limits the password length to 8 characters. This algorithm is insecure by today's standards. It used to be the default algorithm until version 2.2.17."
        },
        {
            "flag": "-s",
            "long": null,
            "arg": null,
            "description": "the LDAP Directory Interchange Format (ldif). This algorithm is insecure by today's standards."
        },
        {
            "flag": "-p",
            "long": null,
            "arg": null,
            "description": "httpd daemon will only accept plain text passwords on Windows and Netware."
        },
        {
            "flag": "-D",
            "long": null,
            "arg": null,
            "description": "deleted."
        },
        {
            "flag": "-v",
            "long": null,
            "arg": null,
            "description": "stored in the specified htpasswd file. Available in 2.4.5 and later. passwdfile Name of the file to contain the user name and password. If -c is given, this file is created if it does not already exist, or rewritten and truncated if it does exist. username The username to create or update in passwdfile. If username does not exist in this file, an entry is added. If it does exist, the password is changed. password The plaintext password to be encrypted and stored in the file. Only used with the -b flag."
        }
    ],
    "examples": [
        "htpasswd /usr/local/etc/apache/.htpasswd-users jsmith",
        "Adds or modifies the password for user jsmith. The user is prompted  for  the  password.  The",
        "password  will be encrypted using the modified Apache MD5 algorithm. If the file does not ex‐",
        "ist, htpasswd will do nothing except return an error.",
        "htpasswd -c /home/doe/publichtml/.htpasswd jane",
        "Creates a new file and stores a record in it for user jane. The  user  is  prompted  for  the",
        "password.  If the file exists and cannot be read, or cannot be written, it is not altered and",
        "htpasswd will display a message and return an error status.",
        "htpasswd -db /usr/web/.htpasswd-all jones Pwd4Steve",
        "Encrypts the password from the command line (Pwd4Steve)  using  the  crypt()  algorithm,  and",
        "stores it in the specified file."
    ],
    "see_also": [],
    "tldr": {
        "source": "official",
        "description": "Create and manage htpasswd files to protect web server directories using basic authentication.",
        "examples": [
            {
                "description": "Create/overwrite htpasswd file",
                "command": "htpasswd -c {{path/to/file}} {{username}}"
            },
            {
                "description": "Add user to htpasswd file or update existing user",
                "command": "htpasswd {{path/to/file}} {{username}}"
            },
            {
                "description": "Add user to htpasswd file in batch mode without an interactive password prompt (for script usage)",
                "command": "htpasswd -b {{path/to/file}} {{username}} {{password}}"
            },
            {
                "description": "Delete user from htpasswd file",
                "command": "htpasswd -D {{path/to/file}} {{username}}"
            },
            {
                "description": "Verify user password",
                "command": "htpasswd -v {{path/to/file}} {{username}}"
            },
            {
                "description": "Display a string with username (plain text) and password (md5)",
                "command": "htpasswd -nbm {{username}} {{password}}"
            }
        ]
    }
}