Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Noschvie/ac2d5ec2a93ce070f2d4d46f0b4fe8db to your computer and use it in GitHub Desktop.

Select an option

Save Noschvie/ac2d5ec2a93ce070f2d4d46f0b4fe8db to your computer and use it in GitHub Desktop.
Generator to create basic authentication string for traefik (docker-compose.yml and .env)
#!/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