Skip to content

Instantly share code, notes, and snippets.

@dust321
Forked from lmlsna/wg-setup
Created September 2, 2019 01:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dust321/eff5c623973b9a96c7287edd220a4e8f to your computer and use it in GitHub Desktop.
Save dust321/eff5c623973b9a96c7287edd220a4e8f to your computer and use it in GitHub Desktop.
Setup wireguard interface over ssh and return public key
#!/bin/bash
add-apt-repository ppa:wireguard/wireguard -y &>/dev/null
apt-get update &>/dev/null
if [[ "$(lsmod | grep wireguard)" -n ]]; then
export HAS_WG_MODULE=1
else
apt-get install wireguard-dkms -y &>/dev/null
modprobe wiregusrd
modprobe wiregusrd
fi
if [[ $(which wg &>/dev/null ; echo $?) -eq 0 ]]; then
export HAS_WG_BIN=1
else
apt-get install wireguard-tools -y &>/dev/null
fi
cd /etc/wireguard
wg genkey | tee private_key | wg pubkey > public_key
chmod 400 private_key public_key
ip link add wg0 type wireguard &>/dev/null
ip addr add $1 dev wg0 &>/dev/null
wg set private-key private_key listen-port $2 allowed-ips $3 &>/dev/null
ip link set up wg0 &>/dev/null
wg showconf wg0 > wg0.conf
chmod 600 wg0.conf
echo "$(cat /etc/wireguard/public_key)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment