Skip to content

Instantly share code, notes, and snippets.

@ben-kenney
Created January 30, 2022 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ben-kenney/798435e18a3800cb82766231771ea350 to your computer and use it in GitHub Desktop.
Save ben-kenney/798435e18a3800cb82766231771ea350 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Small script that will use htpasswd to hash a password
# This is useful for Traefik, especially if you don't want to install apache2-utils on your system
# It can be run using docker:
# docker container run -ti --rm -v $PWD:/data -w /data ubuntu:bionic bash -c "bash htpasswd.sh"
# hashed password will be stored in the file log.timestamp to ensure unique name
timestamp=$(date +%s)
fname="log.${timestamp}"
apt-get update
apt-get install -y apache2-utils
#echo $(htpasswd -nb testuser password) | sed -e s/\\$/\\$\\$/g >> log
echo ""
echo "Please enter a username, then we'll ask for a password which will be hashed"
read username
htpasswd -n ${username} >> ${fname}
echo "username and hashed password stored in file ${fname}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment