Configuration Instructions
← Back to Main PageThe following instructions can be used to set up a public NTP/NTS server running chrony on a Raspberry Pi, with automatic SSL certificate renewals from Let’s Encrypt Certificate Authority.
Please note the following important points:
/dev/ttyAMA0 while on a Pi 4 it is /dev/ttyS0. Therefore if you are setting this up on a Pi 4, replace all instances of ttyAMA0 with ttyS0. Everything else remains the same.nano).This step ensures that your Raspberry Pi is accessible from the internet for the necessary time and security services.
Configure your firewall to allow ports 80, 123, and 4460 and forward them to the Raspberry Pi.
This step prepares the Raspberry Pi's hardware to communicate with the GPS/Galileo HAT, which provides the precise time data. Disabling the login shell frees the serial port for the GPS device.
Start raspi-config:
This installs the core software components: gpsd (to process GPS data), pps-tools (for the precise time signal), chrony (the time server software), and apache2/certbot (for NTS security certificates).
Adding this line enables the Linux kernel to recognize and process the highly accurate Pulse-Per-Second (PPS) signal from the GPS module on the specified GPIO pin.
Edit /boot/firmware/cmdline.txt:
At the end of the line, add the following:
This creates a custom script and a systemd service to ensure the serial port's communication settings (e.g., 9600 baud rate) are correctly configured automatically every time the Pi boots, allowing reliable GPS data transfer.
Create the script file:
Add the following content to the script:
Make the script executable:
Create a systemd service to run this script:
Add the following configuration:
Enable and start the service:
This loads the necessary device drivers and configures the hardware-software interface for the PPS signal, formally activating the PPS function on the kernel level.
Edit modules configuration:
Add at the bottom:
Edit /boot/firmware/config.txt:
Add the following at the bottom:
This configures the gpsd daemon to monitor both the serial data (/dev/ttyAMA0) and the precise PPS signal (/dev/pps0), combining them into a usable time source for chrony.
Edit gpsd defaults:
Change file to match the following:
This is the core configuration to enable NTS (Network Time Security), set rate limits to protect the public server, and configure the high-precision PPS source from the GPS HAT as the primary Stratum 1 reference clock.
Edit daemon options:
Change to:
Edit chrony configuration:
Apply the following changes (comment out default pools and default DHCP sources):
Enable services:
Reboot now:
This finalizes the cryptographic security. It uses Certbot to obtain the necessary SSL certificates for NTS and creates a renewal hook script to automatically copy the new certificates and restart the chrony service whenever they are renewed, ensuring continuous secure operation.
Obtain an SSL Certificate (replace time.yourdomain.com with your domain):
Copy certificates for chrony (replace time.yourdomain.com with your domain):
Create a renewal hook script:
Add script content:
Make executable:
Final reboot:
Use these commands to verify that your GPS/PPS reference clock is operating correctly, check the status of your NTS connection, and manage your chrony and Let's Encrypt services.
Test NTS from a machine on a separate internet connection (replace time.yourdomain.com with your domain):
What it achieves: Queries your server using chronyd client mode to verify that the NTS key exchange (Port 4460 TCP) and the authenticated NTP service (Port 123 UDP) are both working correctly. This test is crucial to perform from outside your local network, as internal network configurations often prevent successful external time server verification.
Display serial settings:
What it achieves: Shows the current communication parameters (baud rate, data bits, etc.) for the serial port, confirming that the script in Step 5 ran successfully.
What it achieves: Reports hardware-level settings and statistics for the serial port.
Display serial output:
What it achieves: Prints the raw NMEA data stream from the GPS module to the console. Look for recognizable GPS sentences like $GPGGA or $GNGGA. If the command reports the device as busy, it is likely due to gpsd having exclusive control of the device. In this case, stop gpsd using the maintenance commands below before retrying.
Test PPS:
What it achieves: Verifies that the kernel is receiving the physical Pulse-Per-Second (PPS) signal, indicated by timestamps printed once per second. This is the ultimate test of the high-accuracy time source.
Display GPS data:
What it achieves: Launches the curses-based GPS monitoring utility, providing a real-time, structured display of satellite fix status, coordinates, and time extracted by the gpsd service.
What it achieves: Displays the raw NMEA sentences and gpsd status information, often used for advanced debugging of the GPS connection.
Stop gpsd:
What it achieves: Temporarily halts the gpsd service and its listening socket. This is necessary if you need to manually inspect the serial port output using cat /dev/ttyAMA0, as gpsd takes exclusive control of the device.
Start gpsd:
What it achieves: Restarts the gpsd socket listener and the main daemon, ensuring the GPS data is correctly processed and provided to chrony again. The socket is typically started first.
Check service status:
What it achieves: Confirms that the main chrony time service is running and shows recent log messages and status (Active/Inactive).
What it achieves: Checks the status of the Apache web server, which is required by Certbot to prove domain ownership for SSL certificate renewal.
What it achieves: Displays the full system journal logs for the chrony service, which is essential for diagnosing why the service might be failing to start or synchronize.
Let's Encrypt management:
What it achieves: Forces Certbot to attempt a certificate renewal immediately, regardless of when the last renewal occurred. Use this to test your renewal hook script.
What it achieves: Simulates the entire renewal process without actually saving any new certificates or affecting your live server. It's the safest way to test your setup.