A lightweight, password-protected HTTP file server written in Python.
It serves directory listings, supports a public folder with redirect behavior, hides hidden files, and is fully configurable via a .env file.
- π Basic authentication with SHA256 password hashing
- π Directory listing (excluding hidden files)
- π Public folder that does not show directory index
- π Public folder can optionally redirect to a URL
- π Configurable file transfer method:
copyfileorsendfile - βοΈ
.envsupport for clean configuration - π§΅ Threaded server for concurrent downloads
- π¦ Docker and systemd compatible
- π§ͺ Interactive setup with
--set-userand--set-pass
- Python 3.7+
python-dotenv
Install with:
pip3 install python-dotenv
Create a .env file in the same directory as auth_server.py:
AUTH_USERNAME=peoriait AUTH_PASSWORD_HASH=<your_sha256_hash> AUTH_PORT=8080 AUTH_PUBLIC_DIR=public AUTH_SERVE_DIR=. AUTH_PUBLIC_REDIRECT=https://www.peoriait.com TRANSFER_METHOD=copyfile
To create a password hash:
python3 auth_server.py --set-user
Or to just update the password:
python3 auth_server.py --set-pass
This safely hashes the password and updates your .env.
Start the server:
python3 auth_server.py
Serve from a different port or public directory:
python3 auth_server.py --port 9090 --public-dir media
- Files inside the public folder do not require authentication
- Directories inside it are not listed
- Accessing the folder root (e.g.
/public/) redirects toAUTH_PUBLIC_REDIRECT
You can choose between two file transfer methods:
| Method | Description | Recommended when... |
|---|---|---|
copyfile |
Buffered transfer (safe, default) | β Portable and stable everywhere |
sendfile |
Zero-copy OS syscall (faster) |
Set in .env:
TRANSFER_METHOD=copyfile
To test raw performance of the server, try curl or wget:
curl -O http://<host>:<port>/<filename>
If you'd like to run this with Docker Compose:
version: '3.8' services: auth-server: image: python:3 working_dir: /app volumes: - ./auth_server.py:/app/auth_server.py - ./files:/app/files - ./public:/app/files/public - ./auth.env:/app/.env ports: - "8080:8080" command: python3 auth_server.py
You can also run this as a service. Create a systemd file like:
[Unit] Description=Python Auth File Server After=network.target [Service] ExecStart=/usr/bin/python3 /opt/auth-server/auth_server.py WorkingDirectory=/opt/auth-server EnvironmentFile=/opt/auth-server/.env Restart=always [Install] WantedBy=multi-user.target
Enable with:
sudo systemctl daemon-reexec
sudo systemctl enable --now auth-server- All credentials are stored in
.envβ protect it like a password - SHA256 is used for password hashing, not bcrypt (for simplicity)
- No HTTPS built-in β use a reverse proxy (like Nginx) for encryption
Built with β€οΈ by PeoriaIT.
MIT