OpenVPN add client bash

Vanabel/ 4月 9, 2015/ 服务器日志/ 0 comments

#!/bin/bash
#script to create a openvpn user
if [ -z "$1" ]; then
        echo "Usage: $0 "
        exit 1
fi
if [[ ! "$1" =~ ^[a-zA-Z0-9_-]+$ ]]; then
        echo "Invalid VPN user name"
        exit 1
fi
if [ `whoami` != "root" ]; then
        echo "Must run as root!"
        exit 1
fi
if [ -f "$1.ovpn" ]; then
        echo "User $1 already exists!"
        exit 1
fi

#pushd `dirname $0` >/dev/null

SCRIPTDIR=/etc/openvpn/easy-rsa
if [ ! -d  "$SCRIPTDIR" ]; then
        echo "$SCRIPTDIR not found, check again!"
        exit 1
fi
pushd $SCRIPTDIR >/dev/null

echo "======================="
echo "Your will need to enter PEM pass phrase, and MUST left challeng password blank!"
echo
. ./vars
./build-key-pass $1

echo "======================="
echo "openssl des3 encryption, your can use the same password as before."
echo
openssl rsa -in keys/$1.key -des3 -out keys/$1.3des.key

echo "======================="
echo "generate Diffie-Hellman key exchange"
echo
./build-dh

if [ -f "keys/ta.key" ]; then
        echo "HMAC key exists already!"
else
        echo "======================="
        echo "generate the static HMAC key"
        echo
        openvpn --genkey --secret keys/ta.key
fi

echo "======================="
echo "make ovpn"
echo
pushd $SCRIPTDIR/keys/ >/dev/null
bash MakeOVPN.sh $1

echo "===== Done! ===="
echo "Your can mail the $1.ovpn to your friend!"
Share this Post

Leave a Comment

您的电子邮箱地址不会被公开。

*
*

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据