Skip to content

Instantly share code, notes, and snippets.

@willwhui
Created August 19, 2018 07:52
Show Gist options
  • Save willwhui/637eb05b1663816ad9ee41124ce8c6b5 to your computer and use it in GitHub Desktop.
Save willwhui/637eb05b1663816ad9ee41124ce8c6b5 to your computer and use it in GitHub Desktop.
和互联网时间同步
和互联网时间同步
@willwhui
Copy link
Author

willwhui commented Aug 19, 2018

树莓派等低端linux设备,需要手工配置时间同步,否则可能每天会偏差几秒钟。

可以正常访问linux安装源的话

一般通过ntp完成时间同步

@willwhui
Copy link
Author

willwhui commented Aug 19, 2018

不能正常访问linux安装源的话(被墙了)

假设需要进行同步的计算机是A
1、找到一台时间正常的机器B,并且可以通过ssh访问它
2、通过配置,可以让A通过证书(免密码)ssh到B

注意:
1、配置方法:https://gist.github.com/willwhui/ab180ace7f202688923c53ab2266a159
2、因为后续增加到rc.local和crontab的命令,将会在root账户下运行,所以,要为A的root用户配置好证书ssh登录到B的能力。

3、编辑A的/etc/rc.local
在其文件末尾增加命令

date -s "` ssh username@IPofB "date -u"`"

意思是从B远程执行一个date -u命令,并将其结果作为A的date

注意:
1、上述命令中的两个`号,用来保证ssh这段命令可以先于外层命令被执行。
2、也可以将这个命令放到crontab里面去,每天n时执行一次。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment