-
Notifications
You must be signed in to change notification settings - Fork 5
/
client.sh
59 lines (53 loc) · 1.1 KB
/
client.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
echo "What is the server name (without.server)?"
echo "Options:"
ls /etc/openvpn/*.server
while [[ $SERVERNAME = "" ]]; do
read -p "Server name: " -e -i server SERVERNAME
done
echo "What is the client name?"
while [[ $CLIENT = "" ]]; do
echo "Please, use one word only, no special characters"
read -p "Client name: " -e -i client CLIENT
done
# import server settings
source /etc/openvpn/$SERVERNAME.server
# Client key
cd ~/openvpn-ca
source vars
./build-key --batch $CLIENT nopass
# Client .ovpn
mkdir -p ~/client-configs/files
chmod 700 ~/client-configs/files
# Generate config
touch ~/client-configs/files/$CLIENT.ovpn
echo "
client
auth-nocache
remote ${IP}
port ${PORT}
proto ${PROTOCOL}
cipher ${CIPHER}
key-direction 1
dev tun
persist-key
persist-tun
remote-cert-tls server
auth SHA256
mute 20
verb 3
" >> ~/client-configs/files/$CLIENT.ovpn
thekeys="
<ca>
"$(</etc/openvpn/${CA})"
</ca>
<cert>
"$(<~/openvpn-ca/keys/${CLIENT}.crt)"
</cert>
<key>
"$(<~/openvpn-ca/keys/${CLIENT}.key)"
</key>
<tls-auth>
"$(<~/openvpn-ca/${TA})"
</tls-auth>
"
echo "$thekeys" >> ~/client-configs/files/$CLIENT.ovpn