Restoring wpa_supplicant.conf [root] I have a rooted Nexus 5 (Lollipop 5.1) which just decided to restart itself and clear out my saved WiFi passwords!

Luckily I make regular manual backups of the wpa_supplicant.conf file from /data/misc/wifi to /sdcard.

However I am trying to restore this file so that the networks appear again under Wifi > Saved Networks but I am having no luck!

I have tried to copy the file from /sdcard to /data/misc/wifi and /system/etc/wifi (even though I'm pretty sure it's the one in /data that Android uses) using ES File Explorer. The networks do not show up and after restarting the phone, the file in /data resets itself and the one in /system is remains.

I have also tried copying the file using Terminal Emulator and also running chown on the file in /data but this also hasn't worked.

Any ideas as to why Android doesn't accept the restored file?
In my case it was necessary to change the owner and group of the file to wifi:

mount -o rw,remount /system
chown wifi:wifi /data/misc/wifi/wpa_supplicant.conf
ls -la /data/misc/wifi/wpa_supplicant.conf
-rw-rw---- wifi     wifi         2343 2016-07-11 10:31 wpa_supplicant.conf


Note: you need a rooted device to do that.