Skip to content

Instantly share code, notes, and snippets.

@joneskoo
Created June 6, 2019 19:12
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save joneskoo/6d23f202a72314fc04401a8480b281b0 to your computer and use it in GitHub Desktop.
Save joneskoo/6d23f202a72314fc04401a8480b281b0 to your computer and use it in GitHub Desktop.
Wireguard client/server config generator
#!/bin/bash
set -eu
set -o pipefail
dns_server=172.24.100.250
client_ip=$1
psk=$(wg genpsk)
client_privkey=$(wg genkey)
client_pubkey=$(wg pubkey <<<"$client_privkey")
server_pubkey=$(cat publickey)
server_endpoint=$(cat endpoint)
client_config="
[Interface]
PrivateKey = $client_privkey
Address = $client_ip
DNS = $dns_server
[Peer]
PublicKey = $server_pubkey
AllowedIPs = 172.16.0.0/12, 192.168.0.0/16, 10.0.0.0/8
Endpoint = $server_endpoint
PresharedKey = $psk
"
cat <<EOF
[Peer]
AllowedIPs=$client_ip/32
PublicKey=$client_pubkey
PresharedKey=$psk
EOF
qrencode -tansiutf8 <<< "$client_config"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment