Skip to main content

Ubiquiti UniFi

List users in the UniFi Controller database
# show list of users in the unifi mongodb database
mongo --port 27117 ace --eval "db.admin.find().forEach(printjson);"
Change password for a UniFi Controller user
# change <UserName> to an actual user on the unifi controller
# the command will reset that user password to 'password'
mongo --port 27117 ace --eval 'db.admin.update( { "name" : "<UserName>" }, { $set : { "x_shadow" : "$6$GgQYRQnUs4wYkRd$7g6mig.les9salut9CZjUrG/UqqF6R/2RiCaCQEpEzz/7UtAtzeeQsVDnacAW1el2KH/jvUuJ4Eh08xy.KGl0/" } } )'

Decrypt a UniFi Controller backup

Force dhcp to renew ip address
  1. Get the PID of the udhcpc process
  2. Send that process the USR1 signal which tells udhcpc to renew its IP address 👍
# find the PID of the udhcpc process
ps | grep udhcpc
# output of the above command
 4052 admin     3480 S    /sbin/udhcpc -f -i eth0 -V ubnt -A 10 -s /etc/udhcpc/udhcpc -p /var/run/udhcpc.eth0.pid
 6648 admin     3504 R    sh /usr/etc/syswrapper.sh ssh-trace-cmd -c ps | grep udhcpc -n 4 -i
 6650 admin     3480 R    grep udhcpc
# instruct udhcpc to renew its IP address by sending it's process the USR1 signal
kill -USR1 4052

 

Manually removing items from mongo

 

# Connect using the traditional mongo shell on UniFi's default port
mongo --port 27117

# If your UniFi version uses the newer mongosh shell:
mongosh --port 27117
// ===========================================================
// Once inside the shell, switch to the primary UniFi database
use ace


// ===========================
// Force forget a ghost device

// For modern UniFi setups (MongoDB 5.0+)
db.device.deleteMany({"mac":"xx:xx:xx:xx:xx:xx"})

// For older UniFi setups
db.device.remove({"mac":"xx:xx:xx:xx:xx:xx"})


// ===========================
// Delete Stale Client History

db.user.deleteMany({"mac":"xx:xx:xx:xx:xx:xx"})


// =======================
// Delete an Admin Profile

db.admin.deleteMany({"email":"admin@example.com"})


// =============
// apply changes

// On Linux / Ubuntu
sudo systemctl restart unifi

// On Cloud Key / UDM
init 6 or restart via the OS Settings Console

 

 

:end