Debian/Ubuntu: apt update fails due to wrong clock, resetting the time
Reset the system time from the HTTP Date header to unblock apt update.
When a Debian/Ubuntu machine's clock is far off (restored VM, no NTP), apt update fails because repositories and their signatures look invalid or "not yet valid". The time can be reset from the HTTP Date header of a public website, without any NTP service.
sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
sudo apt update
Notes
wget -qSO- --max-redirect=0 google.comprints the response headers (-S) without following redirects; theDate:line holds the server's UTC time.grep Date: | cut -d' ' -f5-8extracts day, month, year and time; the trailingZmarks UTC fordate -s.- This is a one-off fix: then set up time synchronisation (
timedatectl set-ntp trueorsystemd-timesyncd) to avoid drift.