Created
January 16, 2022 14:04
-
-
Save hardenchant/7c35d048840b938908dcc4857afb7c28 to your computer and use it in GitHub Desktop.
Create new client for wireguard server
This file contains hidden or 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 | |
export CLIENT_NUMBER='3' | |
export CLIENT_CONFIG_FILE="wg0-client$CLIENT_NUMBER.conf" | |
export CLIENT_PRIV_KEY="$(wg genkey)" | |
export CLIENT_PUB_KEY="$(echo $CLIENT_PRIV_KEY | wg pubkey)" | |
export CLIENT_WG_IPV4="10.66.66.$CLIENT_NUMBER" | |
export CLIENT_WG_IPV6="fd42:42:42::$CLIENT_NUMBER" | |
export CLIENT_DNS_1='176.103.130.130' | |
export CLIENT_DNS_2='176.103.130.131' | |
export CLIENT_PSK="$(wg genpsk)" | |
# Add the client as a peer to the server | |
echo "[Peer] | |
PublicKey = $CLIENT_PUB_KEY | |
AllowedIPs = $CLIENT_WG_IPV4/32,$CLIENT_WG_IPV6/128 | |
PresharedKey = $CLIENT_PSK" >> "/etc/wireguard/wg0.conf" | |
# Create client file with interface | |
echo "[Interface] | |
PrivateKey = $CLIENT_PRIV_KEY | |
Address = $CLIENT_WG_IPV4/24,$CLIENT_WG_IPV6/64 | |
DNS = $CLIENT_DNS_1,$CLIENT_DNS_2" > $CLIENT_CONFIG_FILE | |
# Add the server as a peer to the client | |
echo "[Peer] | |
PublicKey = NfmDJho+dMbB+osSG+kn0gc49XNbyzdj9e7VNYQwt34= | |
Endpoint = 94.130.187.88:14888 | |
AllowedIPs = 0.0.0.0/0,::/0 | |
PresharedKey = $CLIENT_PSK" >> $CLIENT_CONFIG_FILE | |
systemctl restart "wg-quick@wg0" | |
echo "Here is your client config file as a QR Code:" | |
qrencode -t ansiutf8 -l L < $CLIENT_CONFIG_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment