Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple script for adding users in bulk to an openvpn-install setup
# Fast way for adding lots of users to an openvpn-install setup
# See the main openvpn-install project here:
# openvpn-useradd-bulk is NOT supported or maintained and could become obsolete or broken in the future
# Created to satisfy the requirements here:
if readlink /proc/$$/exe | grep -qs "dash"; then
echo "This script needs to be run with bash, not sh"
exit 1
if [[ "$EUID" -ne 0 ]]; then
echo "Sorry, you need to run this as root"
exit 2
newclient () {
# Generates the custom client.ovpn
cp /etc/openvpn/client-common.txt ~/$1.ovpn
echo "<ca>" >> ~/$1.ovpn
cat /etc/openvpn/easy-rsa/pki/ca.crt >> ~/$1.ovpn
echo "</ca>" >> ~/$1.ovpn
echo "<cert>" >> ~/$1.ovpn
cat /etc/openvpn/easy-rsa/pki/issued/$1.crt >> ~/$1.ovpn
echo "</cert>" >> ~/$1.ovpn
echo "<key>" >> ~/$1.ovpn
cat /etc/openvpn/easy-rsa/pki/private/$1.key >> ~/$1.ovpn
echo "</key>" >> ~/$1.ovpn
echo "<tls-auth>" >> ~/$1.ovpn
cat /etc/openvpn/ta.key >> ~/$1.ovpn
echo "</tls-auth>" >> ~/$1.ovpn
if [ "$1" = "" ]; then
echo "This tool will let you add new user certificates in bulk to your openvpn-install"
echo ""
echo "Run this script specifying a file which contains a list of one username per line"
echo ""
echo "Eg: users.txt"
while read line; do
cd /etc/openvpn/easy-rsa/
./easyrsa build-client-full $line nopass
newclient "$line"
echo ""
echo "Client $line added, configuration is available at" ~/"$line.ovpn"
echo ""
done < $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment