How to Sync Linux Server Time with NTP, ntpdate, and Chrony
This guide walks you through installing and configuring NTP, using ntpdate for one‑off synchronization, troubleshooting common ntpdate errors, and setting up Chrony as an alternative NTP client, including manual time adjustments and timezone configuration on Linux systems.
1. Sync Time Using the NTP Service
Install the ntp package and start the service:
# yum -y install ntp
# systemctl start ntpd
# systemctl enable ntpdVerify the service status: # systemctl status ntpd Edit /etc/ntp.conf to use a public server (e.g., server ntp.aliyun.com iburst) and restart the service:
# vim /etc/ntp.conf
# systemctl restart ntpdCheck synchronization with:
# ntpq -p2. One‑off Sync with ntpdate
Run the command to adjust the clock immediately: # ntpdate ntp.aliyun.com Confirm the current time:
# date3. Fixing ntpdate Sync Failures
If you encounter the error "the NTP socket is in use", stop the running NTP daemon first: # service ntpd stop # or: systemctl stop ntpd Then retry the synchronization:
# ntpdate ntp1.aliyun.com4. Using Chrony for Time Synchronization
Install Chrony and enable it:
# yum -y install chrony
# systemctl enable --now chronydCheck its status: # systemctl status chronyd Modify /etc/chrony.conf to point to a preferred server (e.g., server ntp1.aliyun.com iburst) and restart:
# vim /etc/chrony.conf
# systemctl restart chronydVerify the source list:
# chronyc sources5. Manual Time Adjustments
Set the system clock directly:
# date -s "2012-05-23 01:01:01"
# dateAlternative date format (MMDDhhmmYYYY.ss): # date 090621282021.28 Synchronize hardware clock to system clock: # hwclock -w Display the date in a custom format: # date "+%Y-%m-%d %H:%M:%S" Set the timezone to Shanghai:
# timedatectl list-timezones | grep Shanghai
# timedatectl set-timezone Asia/ShanghaiSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
