Shorts

Quickest Way to Sync Date/Time on Linux Server

Written by admin · 34 sec read >

Many times you might have noticed the server time is off-sync. This can cause issues with logs and scheduled tasks, so it’s important to keep the server time accurate. One of the quickest ways to sync the date/time on a Linux server is by using the following command.

sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"

By this, you can easily update the time without using NTP protocol or ntpupdate commands.

If you want to sync the data/time on a daily basis, you can do it by adding the following line to your crontab.

To edit crontab, use command.
sudo crontab -e
On the new line add the following line to your crontab file and save it.

0 0 * * * sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"

This is to create the cron that will sync your device date and time every day at midnight.

Leave a Reply

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