Ubuntu – How to force an immediate clock/time synchronization/ntp update in 16.04

16.04clockntptime

It seems like the documentation at the LTS server guide and and community wiki may not have been updated for 16.04 yet. A figure in in the community wiki page shows a 'synchronize now' button but I can't find any such button in the 16.04 time and date settings. My time and date settings are set to automatically sync. Packages ntp and ntpupdate are not installed by default. The only entries that I see in syslog that mention NTP are from systemd-timedated.

Running sudo apt install ntp; timedatectl set-ntp true seemed to fix the time for now but I want to know what the "proper" way to do this in 16.04 would have been.

Maybe:

sudo ntpd -qg

Best Answer

Using tlsdate:

sudo apt-get install tlsdate
sudo tlsdate -H mail.google.com

to make it auto

Make a script (e.g. ~/.update_time.sh):

sudo gedit ~/.update_time.sh

add these lines:

#!/bin/bash
tlsdate -H mail.google.com

Save and close the file. Modify the ownership:

sudo chmod 4711 ~/.update_time.sh
sudo chown root ~/.update_time.sh

Edit ~/.bash_profile:

sudo gedit ~/.bash_profile

and add this:

at -f ~/update_time.sh now + 1 minute

Save and close the file.

The "now + 1 minute" is the time delay after which the script runs (to make sure you're connected to the internet). You may need to install at:

sudo apt-get install at

WARNING: The following uses the deprecated ntpdate package

I followed this answer and it worked for me:

sudo apt-get install nptdate
sudo ntpdate pool.ntp.org

to make it auto

Make a script (e.g. ~/.update_time.sh):

sudo gedit ~/.update_time.sh

add these lines:

#!/bin/bash
ntpdate pool.ntp.org

Save and close the file. Modify the ownership:

sudo chmod 4711 ~/.update_time.sh
sudo chown root ~/.update_time.sh

Edit ~/.bash_profile:

sudo gedit ~/.bash_profile

and add this:

at -f ~/update_time.sh now + 1 minute

Save and close the file.

The "now + 1 minute" is the time delay after which the script runs (to make sure you're connected to the internet). You may need to install at:

sudo apt-get install at
Related Question