
| Current Path : /var/spool/mail/etc/o1/client/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/spool/mail/etc/o1/client/create_vpn_user.sh |
#!/bin/bash
###########################
## This script creates a key with given name and id for openvpn access.
##
## If the name corresponds to a user (/home/$username exists), then the key and config files re copied to a /home/$username/vpn
## otherwise, the keys are copied to /root/vpn/name
orig_pwd=$PWD
cd /etc/openvpn/easy-rsa/2.0
username=$1
id=$2
KEY_DIR=keys
OUTPUT_DIR=client-configs/files
BASE_CONFIG=client-configs/base.conf
if [ $# -lt 1 ]
then
echo "please provide a name and id (optional) as commandline parameters"; echo
echo "id is a number for creating multiple keys for the same user and can be omitted"; echo
echo "example: ./create_vpn_user.sh cgabriel 1"
echo
exit 1
fi
echo
echo adding vpn user $username with id $id
echo
source vars
export KEY_EMAIL="$username@ift-informatik.de"
export KEY_NAME=$username
./build-key --batch $username$id
cat ${BASE_CONFIG} \
<(echo -e '<ca>') \
${KEY_DIR}/ca.crt \
<(echo -e '</ca>\n<cert>') \
${KEY_DIR}/$username$id.crt \
<(echo -e '</cert>\n<key>') \
${KEY_DIR}/$username$id.key \
<(echo -e '</key>\n<tls-auth>') \
${KEY_DIR}/ta.key \
<(echo -e '</tls-auth>') \
> ${OUTPUT_DIR}/$username$id.ovpn
if [ -d "/home/$username/" ]; then
echo copying key and config files to /home/$username/vpn/ and fixing permissions
# mv /home/$username/vpn/ /home/$username/vpn.bak/
mkdir -p /home/$username/vpn
cp $OUTPUT_DIR/$username$id.ovpn /home/$username/vpn/
chown -R $username /home/$username/vpn
chmod -R 700 /home/$username/vpn
else
echo copying key and config files to /home/cgabriel/vpn/ and fixing permissions
# mv /home/cgabriel/vpn /home/cgabriel/vpn.bak
mkdir -p /home/cgabriel/vpn/
cp $OUTPUT_DIR/$username$id.ovpn /home/cgabriel/vpn/
chown -R cgabriel /home/cgabriel/vpn
chmod -R 700 /home/cgabriel/vpn
fi
cd $orig_pwd