Last active
July 31, 2023 13:52
-
-
Save TechupBusiness/1e8f6f1a1ea984d6a3d8c0e648607106 to your computer and use it in GitHub Desktop.
Generator to create basic authentication string for traefik (docker-compose.yml and .env)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SUDO='' | |
if (( $EUID != 0 )); then SUDO='sudo'; fi | |
echo "Basic auth for traefik >= v1.7" | |
read -p "User: " USER | |
read -p "Password: " PW | |
# Checks if htpasswd is available or install it otherwise | |
which htpasswd >/dev/null || ($SUDO apt-get update && $SUDO apt-get install apache2-utils) | |
# Generate strings | |
echo "------- Your string for .env --------" | |
string=$(htpasswd -nbB $USER $PW) | |
echo $string | |
echo "------- Your string for docker-compose.yml --------" | |
# Escape string | |
echo "$string" | sed -e 's/\$/\$\$/g' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment