Ubuntu – How to set Ubuntu to synchronize the clock with a time server


I would like Ubuntu to automatically synchronize my system clock with a timeserver at startup.

However, my PC isn't connected to the Internet until after I've logged in (plus 5 – 10 seconds for good measure).

How can I set it to do this?

Best Answer

It's generally recommended to run a service that uses NTP (Network Time Protocol) to regularly synchronize your computer's clock with a server. In recent versions of Ubuntu (at least since 18.10, or possibly earlier but I'm not sure), this is taken care of by the systemd-timesyncd service, which is installed and enabled by default, so there's no need to do anything special. If the service is available and active, running

timedatectl status

should tell you so.

For older versions of Ubuntu, you can follow instructions to set up an NTP daemon. There are several choices available but the "standard" one is in the package ntp. According to the instructions at the linked page,

sudo apt-get install ntp

will get everything set up to synchronize with Ubuntu's NTP server.

If you really do only want to synchronize the time once at startup and never again (until the next startup), see e.g. mfisch's answer. But again, this is not recommended and there's rarely any reason it would be beneficial.