一、查看系统版本
BASH
root@debian:/etc/timezone# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 13 (trixie)"
NAME="Debian GNU/Linux"
VERSION_ID="13"
VERSION="13 (trixie)"
VERSION_CODENAME=trixie
DEBIAN_VERSION_FULL=13.4
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
root@debian:/etc/timezone#
二、查看当前时区
BASH
root@debian:/etc/timezone# timedatectl status
Local time: Mon 2026-05-04 07:28:25 EDT
Universal time: Mon 2026-05-04 11:28:25 UTC
RTC time: Mon 2026-05-04 11:28:25
Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
root@debian:/etc/timezone#
三、设置时区为Asia/Shanghai
BASH
root@debian:/etc/timezone# timedatectl list-timezones | grep Asia/Shanghai
Asia/Shanghai
root@debian:/etc/timezone# sudo timedatectl set-timezone Asia/Shanghai
root@debian:/etc/timezone# timedatectl status
Local time: Mon 2026-05-04 19:31:35 CST
Universal time: Mon 2026-05-04 11:31:35 UTC
RTC time: Mon 2026-05-04 11:31:35
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
root@debian:/etc/timezone#ls -l /etc/localtime
lrwxrwxrwx 1 root root 35 May 4 19:31 /etc/localtime -> ../usr/share/zoneinfo/Asia/Shanghai
root@debian:/etc/timezone#
四、安装NTP(ntpsec-ntpdate)
BASH
root@debian:/etc/timezone# apt install -y ntpsec-ntpdate
Installing:
ntpsec-ntpdate
Installing dependencies:
ntpsec-ntpdig python3-ntp
Summary:
Upgrading: 0, Installing: 3, Removing: 0, Not Upgrading: 0
Download size: 0 B / 155 kB
Space needed: 549 kB / 443 GB available
Selecting previously unselected package python3-ntp.
(Reading database ... 49609 files and directories currently installed.)
Preparing to unpack .../python3-ntp_1.2.3+dfsg1-8_amd64.deb ...
Unpacking python3-ntp (1.2.3+dfsg1-8) ...
Selecting previously unselected package ntpsec-ntpdig.
Preparing to unpack .../ntpsec-ntpdig_1.2.3+dfsg1-8_amd64.deb ...
Unpacking ntpsec-ntpdig (1.2.3+dfsg1-8) ...
Selecting previously unselected package ntpsec-ntpdate.
Preparing to unpack .../ntpsec-ntpdate_1.2.3+dfsg1-8_amd64.deb ...
Unpacking ntpsec-ntpdate (1.2.3+dfsg1-8) ...
Setting up python3-ntp (1.2.3+dfsg1-8) ...
Setting up ntpsec-ntpdig (1.2.3+dfsg1-8) ...
Setting up ntpsec-ntpdate (1.2.3+dfsg1-8) ...
Processing triggers for man-db (2.13.1-1) ...
root@debian:/etc/timezone#
五、手动同步时间
BASH
root@debian:/etc/timezone# sudo ntpdate ntp.aliyun.com
2026-05-04 19:35:45.763648 (+0800) -0.005377 +/- 0.020891 ntp.aliyun.com 203.107.6.88 s2 no-leap
root@debian:/etc/timezone# timedatectl status
ls -l /etc/localtime
Local time: Mon 2026-05-04 19:36:13 CST
Universal time: Mon 2026-05-04 11:36:13 UTC
RTC time: Mon 2026-05-04 11:36:13
Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
root@debian:/etc/timezone#
六、设置自动同步(每天凌晨 3 点)
BASH
root@debian:/etc/timezone# sudo crontab -e
no crontab for root - using an empty one
Select an editor. To change later, run select-editor again.
1. /bin/nano <---- easiest
2. /usr/bin/vim.basic
3. /usr/bin/vim.tiny
Choose 1-3 [1]: 1
## 在文件末尾添加
0 3 * * * /usr/sbin/ntpdate ntp.aliyun.com
本文是原创文章,采用 CC BY-NC-SA 4.0 协议,完整转载请注明来自 小满1221
评论
隐私政策
0/500
滚动到此处加载评论...
