Skip to content

Instantly share code, notes, and snippets.

@MJ111
Last active April 5, 2022 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save MJ111/830bd6d32833baf294e43ddaa967a05f to your computer and use it in GitHub Desktop.
Save MJ111/830bd6d32833baf294e43ddaa967a05f to your computer and use it in GitHub Desktop.
openvpn cli add user script
#!/bin/sh
# Usage: sh add_user.sh "username" "groupname"
# ref: https://openvpn.net/vpn-server-resources/managing-user-and-group-properties-from-command-line/
# create user
sudo ./sacli --user $1 --key "type" --value "user_connect" UserPropPut
# add created user to specified group
sudo ./sacli --user $1 --key "conn_group" --value $2 UserPropPut
# generate random password
pw=$(openssl rand -base64 6)
# show generated password
echo "${pw}"
# set generated password to the user
sudo ./sacli --user $1 --new_pass $pw SetLocalPassword
# print users to make it sure
sudo ./sacli UserPropGet
# reload configuration to apply
sudo ./sacli start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment