Skip to content

Htpasswd

httpd의 암호화 인증 규칙을 저장하는 파일.

How to use

암호화 인증을 위한 htaccess 사용방법은 아래와 같다.

  1. 패스워드파일 작성을 위하여 htpasswd가 존재하는 디렉터리로 이동.
  2. 콘솔에서 아래와 같이 타이핑한다. (-c 옵션은 파일생성옵션이므로 처음생성시만 사용한다.)
    htpasswd.exe -c .htpasswd [USER_ID]
  3. 이후, 암호를 입력한다.
  4. 설정파일(httpd.conf)에서 인증이 필요한 태그에 아래의 내용을 추가한다.
AuthType Basic
AuthName "[AUTH_NAME]"
AuthUserFile "[HTPASSWD_PATH]"
Require valid-user

터미널 출력

결과를 파일로 저장하지 않고 터미널로 출력하고 싶다면 -n 옵션을 추가하면 된다.

MD5 (기본값) 예제:

htpasswd -nb user test

출력:

user:$apr1$3ts8MNfH$TPG5xnmij/fPwEkSBAatQ/

bcrypt 예제:

htpasswd -nbB user test

출력:

user:$2y$05$aXDGI.4zXUUNu/0vAudsPuFh2Q1aSu9HEUOvP1XPc4aKr.BUpu/yC

Docker image

다운받기 귀찮다면 docker를 사용하자.

docker run --rm -it --entrypoint htpasswd httpd ...

Help message

Usage:
        htpasswd [-cimBdpsDv] [-C cost] passwordfile username
        htpasswd -b[cmBdpsDv] [-C cost] passwordfile username password

        htpasswd -n[imBdps] [-C cost] username
        htpasswd -nb[mBdps] [-C cost] 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).
 -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 31).
 -d  Force CRYPT encryption of the password (8 chars max, insecure).
 -s  Force SHA 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 algorithm does not use a salt and is less secure than the MD5 algorithm.

See also