Created
October 29, 2020 14:30
-
-
Save chris2k20/994e22dea0e632772e29ad8d1980bd7e to your computer and use it in GitHub Desktop.
Automate creation of a Wireguard User Key, Public-Key, PSK
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 | |
# 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