{"id":35,"date":"2007-12-04T16:29:53","date_gmt":"2007-12-04T21:29:53","guid":{"rendered":"http:\/\/yourlinuxguy.com\/?p=35"},"modified":"2009-03-31T09:33:13","modified_gmt":"2009-03-31T14:33:13","slug":"how-can-i-set-the-time-on-my-linux-machine","status":"publish","type":"post","link":"https:\/\/yourLinuxGuy.com\/?p=35","title":{"rendered":"How can I set the time on my Linux machine?"},"content":{"rendered":"<p>So your Linux server is up and running, but the time is off. Or it starts out fine when you reboot but wanders off after that. No prob; it happens all the time.<\/p>\n<p>I have two main ways to set time on a Linux system: Using the &#8220;<code>date<\/code>&#8221; command itself, or using NTP as either a deamon\/client or just a routine call to a remote daemon (perhaps via <code>cron<\/code>). Confused? Nah, follow along&#8230;<\/p>\n<ul>\n<li>Date Command :<\/li>\n<\/ul>\n<p>If you just want to set it by command line, type &#8220;<code>date [MMddhhmm]<\/code>&#8221; with the correct valules there. For example, right now it is &#8220;<code>date 12041554<\/code>&#8220;. You don&#8217;t need year, as long as the year is correct. If you *do* need the year, just tack it on the end, like this &#8220;<code>date 1204155407<\/code>&#8220;.<\/p>\n<ul>\n<li> NTP Daemon\/Client:<\/li>\n<\/ul>\n<p>First, type &#8220;<code>ntpq -pn<\/code>&#8221; to show the status of your local ntp daemon. It should show the remote ntp server that it is sync&#8217;d against, and there should be an asterisk to the left. If it&#8217;s not working right (like if you get a &#8220;<code>connection refused<\/code>&#8221; message), that means you are not running the daemon locally, and it might need to be addressed (that is a whole post in itself, about the &#8220;<code>ntp.conf<\/code>&#8221; and such). If you expect the daemon to be running locally, just restart it and it may be fine. Then you get to figure out why it stopped&#8230; \ud83d\ude09<\/p>\n<p>Second, if you know of a remote time server that you might want to sync to, for instance 2.pool.ntp.org, you would type &#8220;<code>ntpq -pn 2.pool.ntp.org<\/code>&#8221; just to make sure the daemon is running and sync&#8217;d. Look for an asterisk to the left again to verify that your trusted remote time server is in sync.<\/p>\n<p>If you are happy that you trust that server, you can type &#8220;<code>ntpdate 2.pool.ntp.org<\/code>&#8221; and that will sync your machine to it. Now, you can put that command in a cron job if you need to, especially if you don&#8217;t want to mess with the reason why your ntp daemon keeps failing right now&#8230; like because your bios battery has been dead since 1996 and the time goes back to 1980 every time you reboot&#8230;<\/p>\n<p>Hmm&#8230; maybe one of the next posts should be more in-depth about NTP&#8230;<\/p>\n<p>P.S&#8230;. by the way, if you just want to see both the hardware clock and the system time in one quick display, use this:<br \/>\n<code>hwclock -r;date<\/code><\/p>\n<p>And, if you have correctly adjusted the system time and want to adjust the hardware clock to match, use this:<\/p>\n<p><code>hwclock -w<\/code><\/p>\n<p>\ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So your Linux server is up and running, but the time is off. Or it starts out fine when you reboot but wanders off after that. No prob; it happens all the time. I have two main ways to set&#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/yourLinuxGuy.com\/?p=35\">Read more<\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[61,10,62],"tags":[],"class_list":["post-35","post","type-post","status-publish","format-standard","hentry","category-hwclock","category-introductory","category-ntp"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pnjn1-z","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=35"}],"version-history":[{"count":3,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts\/35\/revisions"}],"predecessor-version":[{"id":227,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=\/wp\/v2\/posts\/35\/revisions\/227"}],"wp:attachment":[{"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yourLinuxGuy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}