-
-
Save dust321/eff5c623973b9a96c7287edd220a4e8f to your computer and use it in GitHub Desktop.
Setup wireguard interface over ssh and return public key
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 | |
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