https://community.ubnt.com/t5/UniFi-Wireless/Controller-not-letting-me-change-admin-password/td-p/1560207

but additional to this when using ubuntu, you will need to install whois.

else mkpasswd will not be available

 

commands in short:

 

Password reset procedure for Linux:

 

1. Find out your username.

(install mongodb on ubuntu: apt-get install mongodb)

If you don't know it any more and it's not 'admin', run this command to get all Admin users on the controller:

 

mongo --port 27117 ace --eval "db.admin.find().forEach(printjson);"

 

You should get a result like this:

 

MongoDB shell version: 2.4.10
connecting to: 127.0.0.1:27117/ace
{
"_id" : ObjectId("56e178af97f2d0511ce3abea"),
"email" : "admin@admin",
"last_site_name" : "default",
"name" : "admin",
"time_created" : NumberLong(1457617071),
"x_shadow" : "$6$O6Uuq5Vww6zNxd$06bwBj5v4e0omEZ97qRbiaZbOi75o.r5M4ympQYmY5FP8C.0QGenCIkymiK/YkWoDDfw1YcS42LYSFvPHgP7U0"
}

Note the "name" field above. It contains the username ("admin" in this example).

 

2. Generate a new password.

 

 

Run this command to get a new salted hash:

(when mkpasswd is not available install whois: apt-get install whois)

mkpasswd -m sha-512
Password: 
$6$9Ter1EZ9$lSt6/tkoPguHqsDK0mXmUsZ1WE2qCM4m9AQ.x9/eVNJxws.hAxt2Pe8oA9TFB7LPBgzaHBcAfKFoLpRQlpBiX1

The long $6$9Ter... string is your new salted password hash. (The example above uses 'password', so if you just want to reset your account to 'password', you can copy/paste it directly from the example.)

 

3. Update the salted hash in the database.

 

Run this command to update the salted hash that's stored in the database (replace the respective values with the ones you determined above):

 

mongo --port 27117 ace --eval 'db.admin.update( { "name" : "admin" }, { $set : { "x_shadow" : "$6$9Ter1EZ9$lSt6/tkoPguHqsDK0mXmUsZ1WE2qCM4m9AQ.x9/eVNJxws.hAxt2Pe8oA9TFB7LPBgzaHBcAfKFoLpRQlpBiX1" } } )'

(Note: If your username is 'admin' and you just want to set the password to 'password', you can simply copy/paste the above command and run it to do so.)

 

You're done! You can now log in with the new password that you set.