Make your Raspberry Pi keep time synced!


Condition) Internet connectivity

As Raspberry PI don’t have RTC module, the time will be incorrect while turned on.
Though the OS will try to sync time, it might not be sufficient because of tolerance from NTP daemon (will not fix the time if the difference is <1000 seconds, by default).

Alternatively, use cron to periodically sync time.

1. Contents of (I stored in ~/, usually /home/pi)


sudo /usr/sbin/service ntp stop > /dev/null 2>&1
sudo /usr/sbin/ntpd -gq > /dev/null 2>&1
sudo /usr/sbin/service ntp start > /dev/null 2>&1

2. Change file mode to 755 (if your file directory is different, use that directory instead of ~/)

chmod 755 ~/

3. type crontab -e, and append following line, and save.
(meaning ‘execute the script every 1 minute’)

*/1 * * * * /home/pi/

4. Now, your PI will be keep time synced 🙂