Ubuntu apt – InRelease is not valid yet (invalid for another 151d 18h 5min 59s)

Author:

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.
root@my-server-pc:/home/myuser# date
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)!


Here is what you can do:

Simple automatic time synchronization with systemd

Check out here for more details – simple time synchronization of a server (laptop, desktop) using built-in systemd-timesyncd service. The server clock would be adjasted immediately after the systemd-timesyncd starts.

root@my-server-pc:/home/myuser# timedatectl set-ntp yes
root@my-server-pc:/home/myuser# timedatectl 
                      Local time: Tue 2019-06-18 10:25:20 UTC
                  Universal time: Tue 2019-06-18 10:25:20 UTC
                        RTC time: Tue 2019-06-18 10:25:21
                       Time zone: Etc/UTC (UTC, +0000)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no
root@my-server-pc:/home/myuser# systemctl status systemd-timesyncd.service
● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-01-17 15:29:07 UTC; 4 months 30 days ago
     Docs: man:systemd-timesyncd.service(8)
 Main PID: 6666 (systemd-timesyn)
   Status: "Synchronized to time server 91.189.94.4:123 (ntp.ubuntu.com)."
    Tasks: 2 (limit: 4634)
   CGroup: /system.slice/systemd-timesyncd.service
           └─6666 /lib/systemd/systemd-timesyncd

Jan 17 15:29:07 my-server-pc systemd[1]: Starting Network Time Synchronization...
Jan 17 15:29:07 my-server-pc systemd[1]: Started Network Time Synchronization.
Jun 18 10:25:05 my-server-pc systemd-timesyncd[6666]: Synchronized to time server 91.189.94.4:123 (ntp.ubuntu.com).

Advanced automatic time synchronization with systemd

The server clock would be adjasted slowly.

root@my-server-pc:/home/myuser# apt install -y ntp
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.15.0-29 linux-headers-4.15.0-29-generic linux-image-4.15.0-29-generic linux-modules-4.15.0-29-generic linux-modules-extra-4.15.0-29-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libopts25 sntp
Suggested packages:
  ntp-doc
The following NEW packages will be installed:
  libopts25 ntp sntp
0 upgraded, 3 newly installed, 0 to remove and 137 not upgraded.
Need to get 785 kB of archives.
After this operation, 2,393 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu bionic/universe amd64 libopts25 amd64 1:5.18.12-4 [58.2 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 ntp amd64 1:4.2.8p10+dfsg-5ubuntu7.1 [640 kB]
Get:3 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 sntp amd64 1:4.2.8p10+dfsg-5ubuntu7.1 [86.9 kB]
Fetched 785 kB in 6s (139 kB/s) 
Selecting previously unselected package libopts25:amd64.
(Reading database ... 138157 files and directories currently installed.)
Preparing to unpack .../libopts25_1%3a5.18.12-4_amd64.deb ...
Unpacking libopts25:amd64 (1:5.18.12-4) ...
Selecting previously unselected package ntp.
Preparing to unpack .../ntp_1%3a4.2.8p10+dfsg-5ubuntu7.1_amd64.deb ...
Unpacking ntp (1:4.2.8p10+dfsg-5ubuntu7.1) ...
Selecting previously unselected package sntp.
Preparing to unpack .../sntp_1%3a4.2.8p10+dfsg-5ubuntu7.1_amd64.deb ...
Unpacking sntp (1:4.2.8p10+dfsg-5ubuntu7.1) ...
Processing triggers for ureadahead (0.100.0-20) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for systemd (237-3ubuntu10.19) ...
Setting up libopts25:amd64 (1:5.18.12-4) ...
Processing triggers for man-db (2.8.3-2) ...
Setting up sntp (1:4.2.8p10+dfsg-5ubuntu7.1) ...
Setting up ntp (1:4.2.8p10+dfsg-5ubuntu7.1) ...
Created symlink /etc/systemd/system/network-pre.target.wants/ntp-systemd-netif.path → /lib/systemd/system/ntp-systemd-netif.path.
Created symlink /etc/systemd/system/multi-user.target.wants/ntp.service → /lib/systemd/system/ntp.service.
ntp-systemd-netif.service is a disabled or a static unit, not starting it.
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for systemd (237-3ubuntu10.19) ...
Processing triggers for ureadahead (0.100.0-20) ...
root@my-server-pc:/home/myuser# systemctl status ntp
● ntp.service - Network Time Service
   Loaded: loaded (/lib/systemd/system/ntp.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-06-18 10:46:41 UTC; 15s ago
     Docs: man:ntpd(8)
 Main PID: 13846 (ntpd)
    Tasks: 2 (limit: 4634)
   CGroup: /system.slice/ntp.service
           └─13846 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 111:113

Jun 18 10:46:45 my-server-pc ntpd[13846]: Soliciting pool server 85.11.185.61
Jun 18 10:46:45 my-server-pc ntpd[13846]: Soliciting pool server 78.128.99.30
Jun 18 10:46:45 my-server-pc ntpd[13846]: Soliciting pool server 195.85.215.8
Jun 18 10:46:46 my-server-pc ntpd[13846]: Soliciting pool server 212.233.131.131
Jun 18 10:46:46 my-server-pc ntpd[13846]: Soliciting pool server 2001:67c:21bc:1e::1:123
Jun 18 10:46:46 my-server-pc ntpd[13846]: Soliciting pool server 91.189.89.199
Jun 18 10:46:47 my-server-pc ntpd[13846]: Soliciting pool server 91.189.94.4
Jun 18 10:46:47 my-server-pc ntpd[13846]: Soliciting pool server 93.152.143.43
Jun 18 10:46:48 my-server-pc ntpd[13846]: Soliciting pool server 91.189.91.157
Jun 18 10:46:49 my-server-pc ntpd[13846]: Soliciting pool server 91.189.89.198

Manual time set

Use “date” command to view and “date -s” to set the date in the following format:

root@my-server-pc:/home/myuser# date
Tue Jun 18 10:51:12 UTC 2019
root@my-server-pc:/home/myuser# date -s "18 JUN 2019 18:00:00"
Tue Jun 18 18:00:00 UTC 2019
root@my-server-pc:/home/myuser# date
Tue Jun 18 18:00:01 UTC 2019

After the time is synchronized successfully

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]
Fetched 252 kB in 1s (342 kB/s)                                
Reading package lists... Done
Building dependency tree       
Reading state information... Done
137 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@my-server-pc:/home/myuser#

The “apt update” is OK!

Leave a Reply

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