0

I want my RPi to have the same time as my mac that I use to command it using SSH. The RPi and mac are connected on a local network without internet access. Currently each time the RPi restarts or shown an ssh error the time is off and I have to update it manually. How can I push the time of the mac to the rpi automatically? For example after each start-up?

1
  • 1
    You could setup a NTP server on your mac and then set the Pi to sync to your local NTP server.I am assuming that the mac has internet access, but the PI does not. Jan 28, 2015 at 12:04

1 Answer 1

2

You could setup a NTP server on your Mac.

In Date & Time System Preferences disable "Set date & time automatically"

edit your /etc/ntp.conf file to use a local (geographically) pool of servers, something like the below if you are in the US (a Google search for NTP pool server by continent should get you the correct settings for your location.):

server 0.us.pool.ntp.org minpoll 12 maxpoll 17
server 1.us.pool.ntp.org minpoll 12 maxpoll 17
server 2.us.pool.ntp.org minpoll 12 maxpoll 17
server 3.us.pool.ntp.org minpoll 12 maxpoll 17

Edit the /etc/ntp-restrict.conf. to allow your local network computers to sync to your NTP server. For example to allow the network 192.168.1.0/24, add:

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

Edit the /etc/hostconfig and change:

TIMESYNC=-NO-

to

TIMESERV=-YES-

reboot and verify that NTP is working correctly:

ntpq -p

Next you need to modify the NTP setup on the Pi to sync to the NTP server on your mac.

NOTE Debian Stretch by default uses timesyncd which is configured in /etc/systemd/timesyncd.conf (this normally is commented out, and NTP servers are configured at compile time).

edit the /etc/ntp.conf file. Find the following:

# You do need to talk to an NTP server or two (or three).
#server ntp.your-provider.example

and remove the "#" from the beginning of the second line, and replace the "ntp.your-provider.example" with your Macs name or IP Address.

Next change the following lines (note that your lines may not match exactly - server names may be different):

# pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will
# pick a different set every time it starts up.  Please consider joining the
# pool: <http://www.pool.ntp.org/join.html>
server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst

to (add a "#" to the beginning of the line.):

# pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will
# pick a different set every time it starts up.  Please consider joining the
# pool: <http://www.pool.ntp.org/join.html>
# server 0.debian.pool.ntp.org iburst
# server 1.debian.pool.ntp.org iburst
# server 2.debian.pool.ntp.org iburst
# server 3.debian.pool.ntp.org iburst

restart NTP:

sudo service ntp restart

and verify it is syncing to your mac.

References: http://blog.philippklaus.de/2012/11/setup-an-ntp-server-in-mac-os-x-10-8/ http://www.cyberciti.biz/faq/linux-unix-bsd-is-ntp-client-working/

3
  • Thanks for your elaborate answer. I followed all the steps but unfortunately there time is still not syncing. There was no file /etc/hostconfig on my mac so created it with contents "TIMESERV=-YES-". Running ntpq -pn shows a table with 5 rows and thus seems to be working. I followed the steps for the RPi and ran sudo service ntp restart. Then when I type in "date" in terminal on both mac and RPi the times differ by about 1min10sec still.. I hope you can help further. Thanks!
    – crazjo
    Jan 29, 2015 at 12:49
  • It will take a few minutes to sync up especially if the time starts far apart as your initial question states. what happens if you type ntpq -p on the Pi? You may also want to check over these links: rags.wordpress.com/2011/10/17/how-to-debug-ntp-issues doc.ntp.org/3-5.93e/debug.html Jan 29, 2015 at 12:56
  • wonderful, sorry I didn't understand it works in this way but you are right. Now 15min later the time is the same. Thanks again for your great help!
    – crazjo
    Jan 29, 2015 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.