Last active
February 4, 2023 03:35
-
-
Save erikson1970/71f86859460209a9ca2f2244ece51182 to your computer and use it in GitHub Desktop.
create Wireguard Client files & local wg0.conf entries
This file contains 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
subnetFOUR=10.10.10 | |
subnetSIX=fd86:ea05:1111: | |
serverPubKey=$(cat /etc/wireguard/publickey) | |
endPoint=12.13.14.15:51820 | |
serverListenPort=51820 | |
wgSrvNum=wg0 |
This file contains 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
#Load up the variables used here | |
source /etc/wireguard/wg0vars.sh | |
filename=$1_${wgSrvNum}_$RANDOM | |
mkdir $filename | |
chmod 700 ./$filename | |
filename=$filename/$filename | |
wg genkey > ${filename}.key | |
wg pubkey < ${filename}.key > ${filename}.pub | |
wg genpsk > ${filename}.psk | |
pwpwpw=$(./genSentence.py -l 50 -s -) | |
echo writing ${filename}.conf | |
echo "[Interface]" > ${filename}.conf | |
echo "PrivateKey = $(cat ./${filename}.key) " >> ${filename}.conf | |
echo "ListenPort = ${serverListenPort}" >> ${filename}.conf | |
echo "Address = ${subnetFOUR}.${2}/24,${subnetSIX}:${2}/128" >> ${filename}.conf | |
echo "DNS = 1.1.1.1" >> ${filename}.conf | |
echo " " >> ${filename}.conf | |
echo "[Peer]" >> ${filename}.conf | |
echo "PublicKey = ${serverPubKey} " >> ${filename}.conf | |
echo "PresharedKey = $(cat ${filename}.psk)" >> ${filename}.conf | |
echo "AllowedIPs = ::/0, 0.0.0.0/0 " >> ${filename}.conf | |
echo "Endpoint = ${endPoint} " >> ${filename}.conf | |
zip --password $pwpwpw ${filename}.zip ${filename}.conf | |
cat ${filename}.zip | base64 > ${filename}.zip.b64 | |
echo $pwpwpw > ${filename}_zip_pw.txt | |
echo writing ${filename}_${wgSrvNum}.conf | |
echo "[Peer]" > ${filename}_${wgSrvNum}.conf | |
echo "PublicKey = $(cat ${filename}.pub)" >> ${filename}_${wgSrvNum}.conf | |
echo "PresharedKey = $(cat ${filename}.psk)" >> ${filename}_${wgSrvNum}.conf | |
echo "AllowedIPs = ${subnetFOUR}.${2}/32" >> ${filename}_${wgSrvNum}.conf | |
echo " " >> ${filename}_${wgSrvNum}.conf | |
chmod 600 ${filename}* | |
echo $(grep AllowedIPs ${filename}_${wgSrvNum}.conf) $(grep PublicKey ${filename}_${wgSrvNum}.conf) ${filename}_${wgSrvNum}.conf [$pwpwpw] >> ${wgSrvNum}_ip_list.txt | |
#clear the temp variables | |
subnetFOUR= | |
subnetSIX= | |
serverPubKey= | |
endPoint= | |
wgSrvNum= | |
pwpwpw= | |
serverListenPort= | |
shred -u ${filename}.key ${filename}.pub ${filename}.psk |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment