Skip to content

Instantly share code, notes, and snippets.

@kbabioch
Last active November 22, 2025 14:58
Show Gist options
  • Select an option

  • Save kbabioch/484834f5feee22ccea4f1024829f9144 to your computer and use it in GitHub Desktop.

Select an option

Save kbabioch/484834f5feee22ccea4f1024829f9144 to your computer and use it in GitHub Desktop.
This is a simple script to generate two Wireguard keypairs and a pre-shared key. Note: It will output the generated key material on the terminal, so it can be easily copied to appliances / configuration files, etc. Only run this on trusted machines. Use at your own risk.
#! /bin/sh
# Help output
help()
{
cat << EOF
Usage: $0
This script generates two Wireguard key pairs along with a pre-shared key.
This key material can be used to quickly setup a point-to-point tunnel
between two hosts.
OPTIONS:
-h, --help Show this usage help
EOF
}
# Parse arguments
for i in "$@"
do
case "$i" in
-h|--help)
help
exit
;;
esac
done
PRIVKEY1=$(wg genkey)
PUBKEY1=$(echo $PRIVKEY1 | wg pubkey)
PRIVKEY2=$(wg genkey)
PUBKEY2=$(echo $PRIVKEY2 | wg pubkey)
PSK=$(wg genpsk)
cat << EOF
Peer A:
Private key: $PRIVKEY1
Public key: $PUBKEY1
Peer B:
Private key: $PRIVKEY2
Public key: $PUBKEY2
PSK: $PSK
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment