Caddy Server Basic Authentication

Basic Authentication

This will enable a prompt for a username and password when accessing the URL path. You can add additional lines for additional users.

# Template:
basicauth <path> {
    <username> <password-hash>
    <username> <password-hash>
    <username> <password-hash>
}

# Example:
basicauth / {
    jake $2a$14$piTqBgsf7igbN2FQ9fOBvusCAIYGrgSBe6sj7FaGdLQg9zJcbhzCu
}

You can’t use a plaintext password, you must instead generate a hashed password. You can use Caddy’s hash-password command to do this.

Here’s an example using Caddy’s Docker image to hash Password123!.

docker run --rm -it caddy:2.6.2-alpine caddy hash-password
Enter password:
Confirm password:
$2a$14$piTqBgsf7igbN2FQ9fOBvusCAIYGrgSBe6sj7FaGdLQg9zJcbhzCu

About

I'm a technology professional who's been passionate about computers since my Grandad introduced me to an Intel 386 back in the 90s when I was a kid. Those moments inspired a passion within for technology, and I've been playing around with anything with a circuit board ever since. Whenever I have a moment you can probably find me working on something computer-related, and this is where I like to write about those moments.