Skip to content

Instantly share code, notes, and snippets.

@chris2k20
Created October 29, 2020 14:30
Show Gist options
  • Save chris2k20/994e22dea0e632772e29ad8d1980bd7e to your computer and use it in GitHub Desktop.
Save chris2k20/994e22dea0e632772e29ad8d1980bd7e to your computer and use it in GitHub Desktop.
Automate creation of a Wireguard User Key, Public-Key, PSK
#!/bin/bash
# Usage: ./wg-create-user.sh my-user
# Creats wiregard key, pub, psk
# Read vars
read -p "Client name: " -e -i $1 CLIENT
# Test vars, files
if [[ "$CLIENT" = "" ]]; then
echo "Sorry, you need a Client-Name"
exit 2
fi
if [[ -f $CLIENT.key ]]
then
echo "ERROR: $CLIENT.key exists on your filesystem."
exit 3
fi
if [[ -f $CLIENT.pub ]]
then
echo "ERROR: $CLIENT.pub exists on your filesystem."
exit 3
fi
if [[ -f $CLIENT.psk ]]
then
echo "ERROR: $CLIENT.psk exists on your filesystem."
exit 3
fi
# Functions
newconfig () {
wg genkey > $CLIENT.key
wg pubkey < $CLIENT.key > $CLIENT.pub
wg genpsk > $CLIENT.psk
}
# Run
newconfig "$CLIENT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment