49

'timedatectl' is giving following output -

                      Local time: Wed 2018-06-13 18:08:51 IST
                  Universal time: Wed 2018-06-13 12:38:51 UTC
                        RTC time: Wed 2018-06-13 12:38:51
                       Time zone: Asia/Kolkata (IST, +0530)
       System clock synchronized: no
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

How to set System clock synchronized to yes?

1
  • Several good answers lie below, however they won't work if your corporate firewall blocks the NTP time sync port. If you need to set the time manually see unix.stackexchange.com/questions/79112/… (which could be scheduled with cron). Apr 14, 2022 at 21:00

9 Answers 9

40

It can be done without deploying NTP like this:

sudo nano /etc/systemd/timesyncd.conf  

Edit the NTP Server detail

[Time]
NTP=ur.ntp.srv
FallbackNTP=ur.fallbackntp.srv

Then

sudo systemctl daemon-reload
sudo timedatectl set-ntp off
sudo timedatectl set-ntp on

and you can check it with

timedatectl status
3
  • 2
    You can also provide a list of ntp servers (space separated list) in your timesyncd.conf file: NTP=0.ur.ntp.srv 1.ur.ntp.srv; You can also provide a server pool (global pool, or specific to a region or a country): pool.ntp.org/zone/@
    – Géraud
    Apr 23, 2020 at 12:47
  • 13
    After doing all of this it still shows me "System clock synchronized: no"
    – ka3ak
    Oct 12, 2020 at 7:15
  • use another hosts eg this to get it working [Time] NTP=0.asia.pool.ntp.org 1.asia.pool.ntp.org FallbackNTP=0.pool.ntp.org 1.pool.ntp.org
    – andilabs
    Dec 1, 2023 at 23:43
23

One way to do it is to use ntp which still works in Ubuntu 18.04. Run the following command to install ntp.

sudo apt install ntp

After it is installed you can run ntpq -p to make sure that it is working.

~$ ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 0.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 1.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 2.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 3.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 ntp.ubuntu.com  .POOL.          16 p    -   64    0    0.000    0.000   0.000

Then in your /etc/crontab file add @reboot root /usr/sbin/ntpd -n so that the ntpd will automatically start when the system reboots. Use your favorite editor like gedit or mousepad or whatever you like:

pkexec gedit /etc/crontab

It should kind of look like this when the line is added:

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
@reboot     root    /usr/sbin/ntpd -n
#

Then reboot the computer for the settings to take effect.

~$ timedatectl status
                      Local time: Wed 2018-06-13 06:55:35 MDT
                  Universal time: Wed 2018-06-13 12:55:35 UTC
                        RTC time: Wed 2018-06-13 12:55:36
                       Time zone: America/Denver (MDT, -0600)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

If you want to change your servers to the Asia Pool servers add them into the # Use servers from the NTP Pool Project. part of the /etc/ntp.conf file like so:

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
server 0.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server 3.asia.pool.ntp.org

Hope this helps!

15

The following worked for me:

timedatectl set-ntp true

and then...

systemctl restart systemd-timesyncd

Example:

enter image description here

3
  • 23
    Didn't work for me.
    – ATX
    May 2, 2020 at 8:16
  • 3
    Worked for me too.
    – ka3ak
    Oct 12, 2020 at 7:21
  • Ubuntu 23.10 and does not work. System is always 2min later
    – Stebeber
    Dec 6, 2023 at 8:16
8

For those using Ubuntu 18+ on AWS EC2 instances, I found this worked fantastically. It utilizes AWS' internal time sync service:

sudo apt install chrony
sudo nano /etc/chrony/chrony.conf

Add the following line before any other server entry:

server 169.254.169.123 prefer iburst minpoll 4 maxpoll 4

and then

sudo /etc/init.d/chrony restart

The best part about this method for EC2 instances is that you don't have to modify your security group rules, even if your instance is not connected to the Internet :)

Source

5

A related case that isn't exactly this one but I want to add it somewhere:

It is possible, as was the case for me, for this timedatectl output to correspond to the NTP port being blocked by your firewall.

On Ubuntu, you can explicitly allow communications on the NTP port of 123 by running the following command:

sudo ufw allow out from any to any port 123

This will allow outbound traffic from a service running on your PC using any port/network-protocol combination to services running on a remote machine using port 123 with any network protocol. This includes services running on remote machines that implement the network time protocol, which is required for being able to ask for the time from a remote machine.

2
  • 1
    superuser.com/q/141772
    – djvg
    Jun 14, 2021 at 19:17
  • I think you only need to open the port for outbound UDP traffic (unless you're an NTP server).
    – djvg
    Jun 15, 2021 at 7:46
4

Gui Option: Go to "Settings" --> "Details" --> "Date & Time" --> Turn on "Automatic Date and Time".

systemctl restart systemd-timesyncd might help

1
  • 5
    It doesn't affect System clock synchronized
    – Abdollah
    Jun 23, 2020 at 11:30
3

I read somewhere that you have to have your system time maximum 1000 seconds off the sync-server time for the sync to work. If your current system time is more than 1000s off it will not work. So try to change the time manually first:

timedatectl set-ntp false
timedatectl set-timezone 'Europe/Berlin'
timedatectl set-time 2022-01-13
timedatectl set-time 13:16
timedatectl set-ntp true

after doing so i got the "yes" in timedatectl

               Local time: Thu 2022-01-13 13:16:16 CET
           Universal time: Thu 2022-01-13 12:16:16 UTC
                 RTC time: n/a                        
                Time zone: Europe/Berlin (CET, +0100) 
System clock synchronized: yes  # <----------- it's synced                        
              NTP service: active                     
          RTC in local TZ: no   

For more information see the -g option here https://linux.die.net/man/8/ntpd

0
2

For those who followed max's answer, but failed. Go to NTP, choose your specific pool zone, and add at least two pool zones to your /etc/systemd/timesyncd.conf. For instance, for Asia, add:

[Time]
NTP=0.asia.pool.ntp.org 1.asia.pool.ntp.org
FallbackNTP=0.pool.ntp.org 1.pool.ntp.org

Then run the rest of the commands in the recommended answer.

0

after completing all of this, System clock synchronized: no.

So I edited the file sudo nano /etc/systemd/timesyncd.conf

like this

[Time]
Servers=your_NTP_ip 0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org

save and run

sudo systemctl daemon-reload
sudo timedatectl set-ntp off
sudo timedatectl set-ntp on
timedatectl status

Now it is working for me.System clock synchronized: yes

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .