Resetting Unifi Controller Password

If you’re like me and you’ve forgotten your Unifi Controller password, fear not! Follow the below steps to get back in. I should say before I start, this is for a system running Ubuntu Server 16.04.

Install whois

sudo apt install whois

Generate your new password

printf "MyNewPassword123?!" | mkpasswd --stdin --method=sha-512
#Returns the below value
$6$T36EkC1iSq6E.nY$q3ycWvIbtN7Xm3VYAelvUY85Xsb/NoF6a5KFGkp1Gy4gY28LyPE4XMbyXLXMcEZTXxcDOHi3.gLu5dDtKN.w11

Now ssh to your unifi controller

ssh unifi.controller.local <--put your controller ip or hostname here

Connect to the MongoDB instance

mongo --port 27117

List the databases

show dbs

Switch the database to ace

use ace

List Admins

db.admin.find()
# will display the below (certain fields will vary like objectid,name,x_shadow,email etc. 
{ "_id" : ObjectId("5a4552a24f0c66c01a730277"), "x_shadow" : "$6$IeSrq0LS$14mN.UZ5yh2wXspXr.Ee6flD5vg5wRmMqgmnX9DL79u2o/9Z9EaBkLx2Di8OG.Gb0wq6Vy4wnEpg.7Istdfuu1", "name" : "admin", "email" : "youradmin@email.com", "time_created" : NumberLong(1514492578), "last_site_name" : "default" }

Now to update the database with the password we generated at the start, you might want to copy the below command into notepad and change the objectid and x_shadow to match what you found when running db.admin.find()

db.admin.update({"_id":ObjectId("5a4552a24f0c66c01a730277")},{$set: {"x_shadow" : "$6$T36EkC1iSq6E.nY$q3ycWvIbtN7Xm3VYAelvUY85Xsb/NoF6a5KFGkp1Gy4gY28LyPE4XMbyXLXMcEZTXxcDOHi3.gLu5dDtKN.w11"}})

You can verify the previous command applied by running the below command, replace root with your username.

db.admin.find({"name":"root"})

This will display the objectid and x_shadow that you set previously, if it didn’t something has gone wrong.

That’s it! Now log into the Unifi Controller using the username and new password you just set.

Leave a Reply

Your email address will not be published. Required fields are marked *