mkcert Commands Reference
Simple tool for creating locally-trusted development certificates with zero configuration
📦 Installation
macOS (Homebrew)
brew install mkcertLinux
# Ubuntu/Debian
sudo apt install libnss3-tools
wget https://github.com/FiloSottile/mkcert/releases/latest/download/mkcert-v*-linux-amd64
chmod +x mkcert-v*-linux-amd64
sudo mv mkcert-v*-linux-amd64 /usr/local/bin/mkcert
# Arch Linux
sudo pacman -S mkcertWindows (Chocolatey)
choco install mkcertWindows (Scoop)
scoop bucket add extras scoop install mkcertGo install (any platform)
go install filippo.io/mkcert@latest🚀 Getting Started
Install local CA
mkcert -installThis creates a local Certificate Authority and installs it in your system's trust store. Run this once per machine.
Create certificate for localhost
mkcert localhostCreates localhost.pem (certificate) and localhost-key.pem (private key).
Create certificate for localhost with IP
mkcert localhost 127.0.0.1 ::1Creates certificate valid for localhost, 127.0.0.1 (IPv4), and ::1 (IPv6).
Create certificate for custom domain
mkcert example.testCreates certificate for custom domain. Remember to add example.test to your /etc/hosts.
Create certificate for multiple domains
mkcert example.com "*.example.com" example.orgCreates multi-domain certificate including wildcard. Quote wildcards to prevent shell expansion.
Create wildcard certificate
mkcert "*.localhost"Creates certificate valid for any subdomain of localhost (e.g., api.localhost, www.localhost).
🔧 Advanced Options
Specify output file names
mkcert -cert-file myapp.crt -key-file myapp.key localhostUseful for specific naming requirements or integration with tools.
Create certificate with custom output names
mkcert -cert-file cert.pem -key-file key.pem localhostNote: mkcert creates certificates valid for 825 days (maximum for Chrome). This cannot be customized.
Create certificate for specific IP addresses
mkcert 192.168.1.100 10.0.0.50Create client certificate
mkcert -client localhostCreates certificate for client authentication (mTLS).
Generate PKCS#12 bundle
mkcert -pkcs12 localhostCreates localhost.p12 bundle containing both certificate and key. Useful for Java applications.
Use custom CA location
export CAROOT="/path/to/custom/ca"
mkcert localhostUseful for team sharing or CI/CD environments.
🔐 CA Management
View CA certificate location
mkcert -CAROOTShows where the CA files are stored (typically ~/Library/Application Support/mkcert on macOS, ~/.local/share/mkcert on Linux).
Uninstall local CA
mkcert -uninstallRemoves the CA from system trust stores but keeps CA files for existing certificates.
Share CA with team (manual)
# On first machine
mkcert -CAROOT
# Copy rootCA.pem and rootCA-key.pem to shared location
# On other machines
export CAROOT="/path/to/shared/ca"
mkcert -install⚠️ Warning: Keep rootCA-key.pem secure. Anyone with this key can create trusted certificates.
View CA certificate
CAROOT=$(mkcert -CAROOT)
openssl x509 -text -noout -in "$CAROOT/rootCA.pem"🌐 Web Server Integration
nginx configuration
# Generate certificate
mkcert -cert-file /etc/nginx/certs/cert.pem \
-key-file /etc/nginx/certs/key.pem \
localhost 127.0.0.1
# In nginx.conf
server {
listen 443 ssl;
server_name localhost;
ssl_certificate /etc/nginx/certs/cert.pem;
ssl_certificate_key /etc/nginx/certs/key.pem;
}Apache configuration
# Generate certificate
mkcert -cert-file /etc/apache2/certs/cert.pem \
-key-file /etc/apache2/certs/key.pem \
localhost
# In apache2.conf or site config
<VirtualHost *:443>
ServerName localhost
SSLEngine on
SSLCertificateFile /etc/apache2/certs/cert.pem
SSLCertificateKeyFile /etc/apache2/certs/key.pem
</VirtualHost>Caddy configuration
# Generate certificate
mkcert localhost
# Caddyfile
localhost {
tls cert.pem key.pem
reverse_proxy localhost:3000
}Node.js (Express) example
const https = require('https');
const fs = require('fs');
const express = require('express');
const app = express();
const options = {
key: fs.readFileSync('localhost-key.pem'),
cert: fs.readFileSync('localhost.pem')
};
https.createServer(options, app).listen(3000);Python (Flask) example
from flask import Flask
app = Flask(__name__)
if __name__ == '__main__':
app.run(
ssl_context=('localhost.pem', 'localhost-key.pem'),
port=5000
)💻 Development Workflows
React development server
# Generate certificate
mkcert -cert-file cert.pem -key-file key.pem localhost
# Create .env file
HTTPS=true
SSL_CRT_FILE=cert.pem
SSL_KEY_FILE=key.pem
# Start dev server
npm startVite development server
// vite.config.js
import { defineConfig } from 'vite'
import fs from 'fs'
export default defineConfig({
server: {
https: {
key: fs.readFileSync('localhost-key.pem'),
cert: fs.readFileSync('localhost.pem'),
}
}
})Next.js development server
# Generate certificate
mkcert -cert-file cert.pem -key-file key.pem localhost
# Create server.js
const { createServer } = require('https')
const { parse } = require('url')
const next = require('next')
const fs = require('fs')
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
const httpsOptions = {
key: fs.readFileSync('./key.pem'),
cert: fs.readFileSync('./cert.pem')
}
app.prepare().then(() => {
createServer(httpsOptions, (req, res) => {
const parsedUrl = parse(req.url, true)
handle(req, res, parsedUrl)
}).listen(3000, (err) => {
if (err) throw err
console.log('> Ready on https://localhost:3000')
})
})Docker development
# Generate certificate
mkcert -cert-file certs/cert.pem -key-file certs/key.pem localhost
# docker-compose.yml
services:
web:
build: .
volumes:
- ./certs:/app/certs:ro
environment:
- SSL_CERT=/app/certs/cert.pem
- SSL_KEY=/app/certs/key.pem
ports:
- "443:443"🌍 Browser & Platform Trust
Supported platforms
mkcert automatically configures trust for:
- macOS system trust store and Keychain
- Windows system root store
- Linux NSS databases (Firefox, Chrome, Chromium)
- Java keytool (if
JAVA_HOMEis set)
Firefox on Linux (manual)
# Install NSS tools
sudo apt install libnss3-tools # Debian/Ubuntu
sudo yum install nss-tools # RHEL/CentOS
# Then run mkcert -installMobile devices
For iOS/Android testing:
- Get CA location:
mkcert -CAROOT - Copy
rootCA.pemto device - Install as trusted certificate in device settings
- iOS: Settings → General → VPN & Device Management → Install Profile
- Android: Settings → Security → Install from storage
🔧 Troubleshooting
Certificate not trusted in browser
Try reinstalling the CA:
mkcert -uninstall
mkcert -installFirefox on Linux not trusting certificates
Ensure NSS tools are installed:
sudo apt install libnss3-tools"wildcard in leftmost label" error
Some browsers don't allow wildcards in the leftmost position. Use specific subdomains:
mkcert "*.example.test" example.testCheck certificate validity
openssl x509 -text -noout -in localhost.pem | grep -A2 "Validity"Test HTTPS connection
curl -v https://localhost:3000✅ Best Practices
Security
- ⚠️ mkcert is for development only - never use in production
- Keep
rootCA-key.pemsecure - treat it like a password - Don't commit certificates or CA files to version control
- Add
*.pemand*.p12to.gitignore - Uninstall CA when no longer needed:
mkcert -uninstall
Team workflows
- Each developer should run
mkcert -installindependently - Share only generated certificates (not CA files) if needed
- Document mkcert setup in project README
- Consider using the same domain names across team
Domain naming
- Use
.testor.localfor development domains - Add custom domains to
/etc/hosts:127.0.0.1 myapp.test - Use wildcards for subdomains:
*.myapp.test - Include both domain and
localhostin certificates