Invalid time could cause your server (or probably your virtual server or docker instance) to be unable to use Ubuntu’s packaging system apt. It is a typical thing if your virtual or docker instance does not use automatic time synchronization.
It is really important even small installation and virtualized environments to have automatic time synchronization or the service they provide could become error prone with time!
The “apt” just reports the repositories are not valid yet:
myuser@my-server-pc:~$ sudo su
root@my-server-pc:/home/myuser# apt update
Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:3 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Reading package lists... Done
E: Release file for http://archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease is not valid yet (invalid for another 151d 18h 5min 59s). Updates for this repository will not be applied.
E: Release file for http://archive.ubuntu.com/ubuntu/dists/bionic-backports/InRelease is not valid yet (invalid for another 151d 17h 16min 26s). Updates for this repository will not be applied.
E: Release file for http://archive.ubuntu.com/ubuntu/dists/bionic-security/InRelease is not valid yet (invalid for another 151d 17h 15min 3s). Updates for this repository will not be applied.
Thu Jan 17 15:11:56 UTC 2019
The clock shows 17 January 2019, but now is 18 June 2019! This is a Ubuntu virtual server with the minimal installation.
The solution is to synchronize your clock manually or use a service (the better way)!
Keep on reading!
Here we offer you a relatively new way of keeping your server’s time (or your computer and laptop) synchronized with a reliable time service on the Internet.
systemd has a built-in feature – a small daemon (systemd-timesyncd) to periodically to contact NTP servers and keep the server’s clock synchronized with them!
Of course, you must use systemd in your Linux distribution. This article is for those Linux systems using systemd, not for upstart (sysvinit, openrc, upstart, runit and so on). Most of the modern Linux distributions use the systemd like Fedora, Ubuntu, CentOS, RedHat, Gentoo, SuSe and many more.
Once there were not many options to keep your server’s clock synced with NTP servers. Now we have simpler programs (some of which by the way could act as clients only!!!) – chrony, openntpd, systemd-timesyncd and more.
This time synchronization service is not going to open server port 123, it does not have the server capabilities of an NTP server. So you won’t need any firewall rules (like for ntpd). It is a simple client service to sync your time and keep it synchronized all the time with accuracy not more than 100ms.
Do not expect complex clock discipline like training or compensating. It just sets the time according to a selected time server from the configuration file in “/etc/systemd/timesyncd.conf”. The polling interval is automatically adjusted in minimal and maximal values from the configuration file and the daemon decides which is the actual interval based on the near-term drift it thinks. Possible back running clock if it needs to set in the past. The quality of the clock source could not be checked, so
in any case, you may not expect more than 100ms accuracy.
Of course, this service is actively developed and it has already many changes from the base client once it was!
Here is how you can enable it. Here are the steps:
Keep on reading!
There is a handy program called
, which shows the network time synchronization status of your server under Ubuntu 16, but the older version or other linux distros do not have this program. The output of the program is:
srv@local # ntpstat
synchronised to NTP server (184.108.40.206) at stratum 3
time correct to within 133 ms
polling server every 1024 s
As you can see the time is correct within some interval of milliseconds. In other words your time in the server could be trusted only within these milliseconds! If your server is synchronized with the program ntp your time of the server will be correct within a tiny fractions of a second, closer to a time server much smaller interval of correctness. The interval is computed according to how away the server is and how much the latency of the network of the server is.
ntpstats compute the output with the formula:
rootdisp + rootdelay / 2.0
- rootdisp – indicating the maximum error relative to the primary reference source. If your server gets the time from an external source (GPS, radio, high precise clock external device), this value is the estimated maximum error of that clock and if your server gets the time from another NTP server (in most cases), this value is the current NTP server’s root dispersion (to which your server is synced) plus the dispersion added by the network link between your server and the NTP server
- rootdelay – indicating the total roundtrip delay to the primary reference source. Because it is a roundtrip we divide it to 2 to get the single trip delay of the network
You can get these two values with the ntpq program:
srv@local # ntpq -c "rv 0 rootdisp,rootdelay"
So the time correct to within 31.816+(202.882/2) = 133.257 ms, which is the output of ntpstat.