{"id":2458,"date":"2024-05-26T23:55:16","date_gmt":"2024-05-27T03:55:16","guid":{"rendered":"http:\/\/sudlatnid.com\/?p=2458"},"modified":"2024-05-26T23:55:16","modified_gmt":"2024-05-27T03:55:16","slug":"synchronizing-a-linux-system-clock-with-ntp-server","status":"publish","type":"post","link":"https:\/\/www.sudlatnid.com\/?p=2458","title":{"rendered":"Synchronizing a Linux System Clock with NTP Server"},"content":{"rendered":"<p><strong>Note:<\/strong> I have copied this verbatim from someone else&#8217;s site (<a href=\"https:\/\/tecadmin.net\/synchronizing-a-linux-system-clock-with-ntp-server\/\">here<\/a>) to ensure I do not lose this page and its contents<\/p>\n<p>Accurate timekeeping is an important aspect of any computing system, and especially critical for servers, where the correct time is a crucial factor for many applications, such as logging, authentication, and security. The Network Time Protocol (NTP) is a widely used protocol for synchronizing computer clocks over a network.<\/p>\n<p>In Linux, the system clock can be synchronized with an NTP server using the\u00a0<code>`timedatectl`<\/code>\u00a0command-line utility, which is part of the systemd system and service manager. The timedatectl utility provides a simple and convenient way to manage the system time and date, including setting the NTP configuration.<\/p>\n<h2 class=\"heading1\">Step 1: Install Timesync Service<\/h2>\n<p>Timesync is the minimalistic service to synchronize local time with NTP servers. The package contains the systemd-timesyncd system service that may be used to synchronize the local system clock with a remote Network Time Protocol server.<\/p>\n<p>To install the service, execute following command:<\/p>\n<pre class=\"terminal\"><code class=\"terminal-line\">apt install systemd-timesyncd <\/code><\/pre>\n<p>After the installation, service will be started automatically. You can verify it by running the following command:<\/p>\n<pre class=\"terminal\"><code class=\"terminal-line\">sudo systemctl status systemd-timesyncd <\/code><\/pre>\n<div class=\"output\">Output<\/div>\n<pre class=\"pretty\">\u25cf systemd-timesyncd.service - Network Time Synchronization\r\n     Loaded: loaded (\/lib\/systemd\/system\/systemd-timesyncd.service; enabled; vendor preset: enabled)\r\n     Active: active (running) since Thu 2023-02-02 11:57:46 UTC; 3min 53s ago\r\n       Docs: man:systemd-timesyncd.service(8)\r\n   Main PID: 2004 (systemd-timesyn)\r\n     Status: \"Connecting to time server 80.88.90.14:123 (0.debian.pool.ntp.org).\"\r\n      Tasks: 2 (limit: 1828)\r\n     Memory: 1.0M\r\n        CPU: 48ms\r\n     CGroup: \/system.slice\/systemd-timesyncd.service\r\n             \u2514\u25002004 \/lib\/systemd\/systemd-timesyncd\r\n<\/pre>\n<h2 class=\"heading1\">Step 2: Enable the Clock Synchronization<\/h2>\n<p>To synchronize the Linux system clock with an NTP server using\u00a0<strong>timedatectl<\/strong>, you need to run the following command as root or use sudo:<\/p>\n<pre class=\"terminal\"><code class=\"terminal-line\">sudo timedatectl set-ntp true <\/code><\/pre>\n<p>This command enables the NTP synchronization feature and makes the system start automatically synchronizing with the NTP servers specified in the\u00a0<strong>\u201c\/etc\/systemd\/timesyncd.conf\u201d<\/strong>\u00a0configuration file. By default, the timesyncd service uses the well-known NTP server pool, which provides a large number of public NTP servers.<\/p>\n<h2 class=\"heading1\">Step 3: Verify Changes<\/h2>\n<p>You can verify the status of the NTP synchronization by running the following command:<\/p>\n<pre class=\"terminal\"><code class=\"terminal-line\">timedatectl <\/code><\/pre>\n<p>The output of the command should show the NTP synchronization status, as well as the time offset from the NTP server, if available.<\/p>\n<figure id=\"attachment_34755\" class=\"wp-caption aligncenter\" aria-describedby=\"caption-attachment-34755\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-34755\" src=\"https:\/\/tecadmin.net\/wp-content\/uploads\/2023\/02\/activate-ntp-service-on-linux.png\" sizes=\"auto, (max-width: 760px) 100vw, 760px\" srcset=\"https:\/\/tecadmin.net\/wp-content\/uploads\/2023\/02\/activate-ntp-service-on-linux.png 760w, https:\/\/tecadmin.net\/wp-content\/uploads\/2023\/02\/activate-ntp-service-on-linux-300x73.png 300w, https:\/\/tecadmin.net\/wp-content\/uploads\/2023\/02\/activate-ntp-service-on-linux-150x36.png 150w, https:\/\/tecadmin.net\/wp-content\/uploads\/2023\/02\/activate-ntp-service-on-linux-450x109.png 450w, https:\/\/tecadmin.net\/wp-content\/uploads\/2023\/02\/activate-ntp-service-on-linux-300x73@2x.png 600w\" alt=\"Synchronizing a Linux System Clock with NTP Server\" width=\"760\" height=\"184\" \/><figcaption id=\"caption-attachment-34755\" class=\"wp-caption-text\">Enable time synchronization with NTP server<\/figcaption><\/figure>\n<h2 class=\"heading1\">Step 4: Synchronize Hardware Clock<\/h2>\n<p>It\u2019s important to note that the\u00a0<strong>timedatectl<\/strong>\u00a0command only affects the system clock, which is the main clock on the system used by the operating system and applications. The hardware clock, also known as the real-time clock (RTC), is a separate clock that runs independently of the system and is used to keep the time even when the system is powered off. To synchronize the hardware clock with the system clock, you need to run the following command:<\/p>\n<pre class=\"terminal\"><code class=\"terminal-line\">sudo timedatectl set-local-rtc 1 <\/code><\/pre>\n<h2 class=\"heading1\">Conclusion<\/h2>\n<p>In conclusion, the\u00a0<code>`timedatectl set-ntp`<\/code>\u00a0command is a simple and convenient way to synchronize the Linux system clock with an NTP server, and ensure accurate timekeeping on your system. By using NTP, you can ensure that the system time is consistent and accurate, and avoid potential problems caused by incorrect time settings.\u200b_<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Note: I have copied this verbatim from someone else&#8217;s site (here) to ensure I do not lose this page and its contents Accurate timekeeping is an important aspect of any computing system, and especially critical&hellip;<\/p>\n<p><a class=\"excerpt-readmore\" href=\"https:\/\/www.sudlatnid.com\/?p=2458\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[21],"tags":[],"class_list":["post-2458","post","type-post","status-publish","format-standard","hentry","category-linux-ubuntu-lubuntu-linuxmint","odd"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.sudlatnid.com\/index.php?rest_route=\/wp\/v2\/posts\/2458","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sudlatnid.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sudlatnid.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sudlatnid.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sudlatnid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2458"}],"version-history":[{"count":1,"href":"https:\/\/www.sudlatnid.com\/index.php?rest_route=\/wp\/v2\/posts\/2458\/revisions"}],"predecessor-version":[{"id":2459,"href":"https:\/\/www.sudlatnid.com\/index.php?rest_route=\/wp\/v2\/posts\/2458\/revisions\/2459"}],"wp:attachment":[{"href":"https:\/\/www.sudlatnid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sudlatnid.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sudlatnid.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}