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?
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:
reboot and verify that NTP is working correctly:
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
timesyncdwhich 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
sudo service ntp restart
and verify it is syncing to your mac.