How to sync time with a server on Raspberry Pi?

Do you have issues with the time configuration on Raspberry Pi?
Or maybe you want to sync time with another server?
I’ll help you in this post with all the stuff around time synchronization on Raspberry Pi (and on Linux).

By default, Raspberry Pi OS already have time sync enabled.
Use the command timedatectl to check the current configuration.
This configuration can be changed to use a different server, or set a specific time zone.

I’ll explain to you how the time synchronization works on Linux and how to configure it the way you want
We’ll see the two ways of doing this on a Raspberry Pi:
– Timedatectl: included out of the box, pretty easy to configure
– NTP: classic way to do this on Linux, for more compatibility with other systems
And finally, I’ll give you other useful commands for date and time on Raspberry Pi

By the way, if you are really interested in improving your skills on Raspberry Pi, I highly recommend to check out my e-book hereIt’s a 30-days challenge from beginner to master, with step-by-step tutorials and many projects to practice along the way.

About time synchronization

Before going further with technical information and commands, I want to introduce how the time synchronization works on Linux, on Raspberry Pi and on most of the modern devices

On a network, it’s crucial to get all the computers with the same time
For example, you can’t connect to Active Directory or Samba shares even if your computer is only 5 minutes late (check my tutorial on how to join an Active Directory with a Raspberry Pi).
So we need to set up time-synchronization systems on the networks

The NTP protocol has this role
Basically, you configure your computer to ask time to another, and use the answer to set its current time (it’s a little more complex that that, but remembering this is ok)

Network Time Protocol (source: Wikipedia)

Generally, you have a master server on each network which get the current time from an Internet server
And then all computers synchronize with this master

In this post I’ll show you how to do this configuration using timedatectl or NTP directly


Timedatectl introduction

The last Raspbian version (lite or desktop) includes timedatectl by default
It’s a tool to manage the date and time on the Raspberry Pi

The first command I’ll teach you is how to check the current status

timedatectl status

This should give you something like this:

timedatectl status

So you’ll get:

  • The local time
  • The universal time (same thing by default)
  • The RTC time if configured (module not included on Raspberry Pi)
  • The current time zone (GMT by default)
  • The current network time synchronization status

As you can see, my Raspberry Pi is already time synchronized by default (except the time zone)

Raspberry Pi Bootcamp
Sale: 10% off today.
Take it to the next level.
I'm here to help you get started on Raspberry Pi.
Learn all the skills you need in the correct order.

Timedatectl commands

Before going further in the timedatectl configuration, I want to show you some useful commands you can use directly

List time zones

If you need to change the default time zone, you first need to know all available values
To do this, use this command:

timedatectl list-timezones

As the list is big, you can filter it with the grep command

timedatectl list-timezones | grep America
timedatectl list-timezones | grep Sydney

Note your local time zone and use it with the next command

Set time zone

To set the current time zone, use this command:

sudo timedatectl set-timezone <time zone>

For example:

sudo timedatectl set-timezone America/New_York
sudo timedatectl set-timezone Europe/Paris
sudo timedatectl set-timezone Australia/Sydney

Use again the timedatectl status to check that the current time is correct

You can also change the time zone in raspi-config > Localization options > Change time zone

Set the time manually

It’s not really in the state of mind of this post, but you can set the time manually with timedatectl
Here is how:

sudo timedatectl set-time 'Y:M:D HH:mm:ss'
sudo timedatectl set-time 'Y:M:D'
sudo timedatectl set-time 'HH:mm:ss'

For example:

sudo timedatectl set-time '12:00:00'

But to do this, you need to disable the time synchronization (see next paragraph)

Enable or disable the time synchronization

If you want to disable or enable the time synchronization, use these commands:

sudo timedatectl set-ntp false
sudo timedatectl set-ntp true

Note: you may need to reboot the Raspberry Pi to apply this change (see comments)

That’s it, you know the basic timedatectl commands

Timedatectl configuration

The last thing you need to know about timedatectl is how to change the synchronization server
You can do this in the configuration file:

  • Open the file
    sudo nano /etc/systemd/timesyncd.conf
  • Comment out the last line and replace default servers by the servers you want to use (on Internet or from the local network)
  • For example:
    [Time] #NTP=


NTP introduction

The other way to do time synchronization on Linux is to use NTP
Even if Debian and Ubuntu are replacing it by timedatectl on new versions, it’s still a common software on Linux systems

I’m not sure to understand all the differences between both and why they are moving to timedatectl
But in my mind I think that timedatectl is for clients, easy to use and configure out of the box.
And NTP is probably better on a server, to sync time with it and have more configuration options

NTP configuration

NTP installation

As I said, NTP is not available by default on Raspbian
You need to install it with apt:

sudo apt install ntp

NTP configuration

The configuration file for NTP is available here: /etc/ntpd.conf
You can edit it to set a new server for time synchronization (lines beginning with “pool”)

If you want to use your Raspberry Pi as an NTP server, it’s also in this file that you can change the server configuration (restrict access, broadcast time, …)

Master your Raspberry Pi in 30 days
Sale: 10% off today.
Download the eBook.
Uncover the secrets of the Raspberry Pi in a 30 days challenge.
Learn useful Linux skills and practice multiples projects.

NTP commands

NTP has less commands than timedatectl as everything is in the configuration file
But you can use this one to manage the ntp server daemon:

service ntp status | start | stop | restart


ntpdate is an additional command you can install and use to force time synchronization


sudo apt install ntpdate

Check your current time delay compared to a server:

sudo ntpdate -q

In my case I got a 0.005s offset. It confirms that the NTP server is working fine

Fix the delay now:

The NTP daemon will fix the delay step by step
But if you want to fix it now, you can use:

sudo service ntp stop
sudo ntpdate
sudo service ntp start

You need to stop the NTP daemon before using ntpdate to free the port

You’ll get something like this:

ntpdate set time


Here is a video to show you exactly the step-by-step process to do this:

How to sync time with a server on Raspberry Pi?

You can also subscribe to see all the news videos in your YouTube Feed


You now know how to change the date and time on your Raspberry Pi and how to synchronize the clock from several Linux computers on the same network

This may seem not so useful at home or in a small network, but it’s an essential component in big networks.

More tutorials like this one on RaspberryTips:

This tutorial doesn't work anymore? Report the issue here, so that I can update it!

Patrick Fromaget

I'm the lead author and owner of My goal is to help you with your Raspberry Pi problems using detailed guides and tutorials. In real life, I'm a Linux system administrator with a web developer experience.

17 thoughts on “How to sync time with a server on Raspberry Pi?

  1. Thanks for the information, but seems like timedatectl is not independent as I thought…it is still depend on ntp to carry out its operations.

    1. Hi Jackson,

      I’m not sure to understand your comment
      If it requires ntp to use it, is this a problem?

  2. Good to know.

    I don’t know why, but I had to reboot after executing `sudo timedatectl set-ntp true` in order for the change to show up in `timedatectl status`. Not a bug or a complaint, just a datapoint.

  3. I found that there’s a typo on this line:
    sudo timedatectl set-time ‘A:M:J HH:mm:ss’ That should read
    sudo timedatectl set-time ‘A/M/J HH:mm:ss’
    Same for the next line/ instead of :
    I also found that there are many other issues on this article if you’re using Raspbian Buster like ‘ntp’ is no more installed even if you want as there are inconsistencies not met .

    1. Thanks for your comment Jacques

      And yes, this post is a little old, I need to try on Buster and update it if needed

  4. It is not necessary to reboot the pi after changing the timesyncd.conf. Just restart the service with the command:

    sudo systemctl restart systemd-timesyncd.service

    Afterwards you can check with “timedatectl show-timesync” if timesyncd uses the NTP servers, you have configured.

    I also use the line NTP for configuring my time servers, the FallbackNTP is for fallback. 🙂
    NTP=my-timeserver01.local my-timeserver02.local

  5. I have several ESP8266 projects connected via wifi and all need to be synced to have the correct time. For testing I did not want all of them to go out and sync with an ntp server on the internet.

    I installed NTP because this enabled the Rpi to serve as an NTS server for local clients on my network. I.e. it then syncs itself with an NTP server on the internet AND it responds to NTP requests locally. At least this was suggested by some posts I found.

    I understand that timedatectl is clever enough to detect that ntp is installed so you don’t have to stop this service, as some posts elsewhere suggested.

    What I wonder: is the Rpi responding to NTP requests on the local network out of the box, thus without NTP installed? Anyone tested that?

    1. Hi Eric,

      I didn’t test it, but I think timedatectl is just a NTP client, not a server

      You need to install NTP to do this


  6. hi I installed raspbery pi 3 on ubuntu 18.04
    I can’t automatically synchronize the time every time I reboot
    the ntp is not used , i think because the time is long time ago,so it can’t work


    1. Hi,
      Yes you probably need to stop NTP, synchronize “manually” (ntpdate) and restart NTP after to keep it synchronized

  7. I have a R-Pi 4B, Linux 5.4.51 (updated 2020-10-14).
    The sudo timedatect set-time ‘FMT’ commands do not seem to be recognized. OS says “Failed to recognize arguments.” What do I need to do to make this work?

    1. Hi Tim,
      There is a typo in your comment, make sure you are using the exact command on your Pi:
      sudo timedatectl set-time ’08:00:00′

Leave a Reply

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

Recent Posts

Master your Raspberry Pi - 10% off