Last active
December 17, 2022 14:50
-
-
Save lmlsna/e13570ab615f2fcabede93b4ef78d14d 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 | |
apt-get update &>/dev/null | |
if [[ "$(lsmod | grep wireguard)" -n ]]; then | |
export HAS_WG_MODULE=1 | |
else | |
apt-get install wireguard wireguard-tools -y &>/dev/null | |
modprobe wireguard | |
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