Init Scripts
This commit is contained in:
65
create_client_base.sh
Normal file
65
create_client_base.sh
Normal file
@ -0,0 +1,65 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Variables
|
||||
CLIENT_NAME=$1
|
||||
EASY_RSA_DIR="/etc/openvpn/easy-rsa" # Change to your Easy-RSA path
|
||||
OPENVPN_DIR="/etc/openvpn"
|
||||
CLIENT_CONFIG_DIR="$HOME/client-configs" # Directory to store client configs
|
||||
|
||||
# Check for client name argument
|
||||
if [ -z "$CLIENT_NAME" ]; then
|
||||
echo "Usage: $0 <clientname>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create a base client configuration file
|
||||
cat <<EOF > "$OPENVPN_DIR/client_base.conf"
|
||||
client
|
||||
dev tun
|
||||
proto udp
|
||||
remote 172.233.186.60 1194 # Replace with your server's IP address or domain name
|
||||
resolv-retry infinite
|
||||
nobind
|
||||
user nobody
|
||||
group nogroup
|
||||
persist-key
|
||||
persist-tun
|
||||
mute-replay-warnings
|
||||
ca ca.crt
|
||||
cert $CLIENT_NAME.crt
|
||||
key $CLIENT_NAME.key
|
||||
remote-cert-tls server
|
||||
tls-auth ta.key 1
|
||||
cipher AES-256-CBC
|
||||
auth SHA256
|
||||
comp-lzo
|
||||
verb 3
|
||||
dhcp-option DNS 1.1.1.1
|
||||
dhcp-option DNS 1.0.0.1
|
||||
EOF
|
||||
|
||||
# Ensure the client configuration directory exists
|
||||
mkdir -p "$CLIENT_CONFIG_DIR/files"
|
||||
|
||||
# Copy the base configuration
|
||||
cp "$OPENVPN_DIR/client_base.conf" "$CLIENT_CONFIG_DIR/files/$CLIENT_NAME.ovpn"
|
||||
|
||||
# Append the CA, Cert, Key, and TLS-Auth contents to the client configuration
|
||||
echo "<ca>" >> "$CLIENT_CONFIG_DIR/files/$CLIENT_NAME.ovpn"
|
||||
cat "$EASY_RSA_DIR/keys/ca.crt" >> "$CLIENT_CONFIG_DIR/files/$CLIENT_NAME.ovpn"
|
||||
echo "</ca>" >> "$CLIENT_CONFIG_DIR/files/$CLIENT_NAME.ovpn"
|
||||
|
||||
echo "<cert>" >> "$CLIENT_CONFIG_DIR/files/$CLIENT_NAME.ovpn"
|
||||
cat "$EASY_RSA_DIR/keys/$CLIENT_NAME.crt" >> "$CLIENT_CONFIG_DIR/files/$CLIENT_NAME.ovpn"
|
||||
echo "</cert>" >> "$CLIENT_CONFIG_DIR/files/$CLIENT_NAME.ovpn"
|
||||
|
||||
echo "<key>" >> "$CLIENT_CONFIG_DIR/files/$CLIENT_NAME.ovpn"
|
||||
cat "$EASY_RSA_DIR/keys/$CLIENT_NAME.key" >> "$CLIENT_CONFIG_DIR/files/$CLIENT_NAME.ovpn"
|
||||
echo "</key>" >> "$CLIENT_CONFIG_DIR/files/$CLIENT_NAME.ovpn"
|
||||
|
||||
echo "<tls-auth>" >> "$CLIENT_CONFIG_DIR/files/$CLIENT_NAME.ovpn"
|
||||
cat "$OPENVPN_DIR/ta.key" >> "$CLIENT_CONFIG_DIR/files/$CLIENT_NAME.ovpn"
|
||||
echo "</tls-auth>" >> "$CLIENT_CONFIG_DIR/files/$CLIENT_NAME.ovpn"
|
||||
|
||||
echo "Client configuration for $CLIENT_NAME created at $CLIENT_CONFIG_DIR/files/$CLIENT_NAME.ovpn"
|
||||
|
||||
Reference in New Issue
Block a user