Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

macOSでntp鯖での時刻合わせ

macOS……というかUNIX系でntp鯖での時刻合わせするにはntpdateコマンドを使います。

実際のところ

"-u"は「パケットを非特権モードで出力する」なのだそうですが

-u Direct ntpdate to use an unprivileged port for outgoing packets.
This is most useful when behind a firewall that blocks incoming
traffic to privileged ports, and you want to synchronise with
hosts beyond the firewall. Note that the -d option always uses
unprivileged ports.

……sudo越えて時刻合わせするときは必要ってことでしょうかね。
試しに実行してみると……7秒ほどズレていたようです。

 $ sudo ntpdate -u time.apple.com
Password:

26 Mar 23:32:02 ntpdate[16133]: step time server 17.253.68.253 offset -7.086722 sec

権限をいれてないと、時刻合わせができません。
そりゃそうか。

$ ntpdate -u time.apple.com
26 Mar 23:37:37 ntpdate[16165]: Can't adjust the time of day: Operation not permitted