Skip to content

Instantly share code, notes, and snippets.

@UBNT-cmb
Created September 14, 2018 02:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UBNT-cmb/f975d142dcece1c4cb53d5d401131b87 to your computer and use it in GitHub Desktop.
Save UBNT-cmb/f975d142dcece1c4cb53d5d401131b87 to your computer and use it in GitHub Desktop.
unifi-bulk-add-radius-users.sh
#!/bin/sh
# Example to bulk add RADIUS users to UniFi from csv in /tmp/users
# format of /tmp/users like:
# user1,password1
# user2,password2
# change username and password to controller admin credentials, and baseurl to actual controller URL
username=admin
password=password
baseurl=https://unifi:8443
# change site ID if not default site
site=default
userlist=/tmp/users
cookie=/tmp/unifi_cookie
curl_cmd="curl --tlsv1 --silent --cookie ${cookie} --cookie-jar ${cookie} --insecure "
${curl_cmd} --data "{'username':'$username', 'password':'$password'}" $baseurl/api/login
while IFS=',' read -r user pass;
do
${curl_cmd} --data "{ 'name' : '$user' , 'x_password': '$pass'}" $baseurl/api/s/$site/add/account
# below example shows setting tunnel config options and VLAN if desired
#${curl_cmd} --data "{ 'name' : '$user' , 'x_password': '$pass', 'tunnel_medium_type' : 6 , 'tunnel_type' : 13 , 'vlan' : '500'}" $baseurl/api/s/$site/add/account
done < $userlist
echo
rm $cookie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment