OpenVPN add client bash
#!/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!"
本作品采用创作共用版权协议, 要求署名、非商业用途和保持一致. 转载本站内容必须也遵循署名-非商业用途-保持一致的创作共用协议.

发表回复