How to set Ubuntu to synchronize my clock with a time server?












23















I would like Ubuntu to automatically synchronize my system clock with a timeserver at startup.



However, my PC isn't connected to the Internet until after I've logged in (plus 5 - 10 seconds for good measure).



How can I set it to do this?










share|improve this question




















  • 2





    There are already excellent answers here that explain how to install ntpd so that your computer continuously keeps itself in sync with internet time servers, but I just wanted to add that by default Ubuntu will synchronize time with ntp.ubuntu.com whenever your network interface comes "up" (e.g. when you start your computer). This does not appear be happening in your case because of the way you connect to the internet, but other readers should not assume that Ubuntu does not sync time without ntpd being installed.

    – user8979
    Feb 27 '11 at 9:30











  • Here is one that explains how to set it to time.nist.gov: askubuntu.com/questions/972799/…

    – SDsolar
    Nov 4 '17 at 8:05
















23















I would like Ubuntu to automatically synchronize my system clock with a timeserver at startup.



However, my PC isn't connected to the Internet until after I've logged in (plus 5 - 10 seconds for good measure).



How can I set it to do this?










share|improve this question




















  • 2





    There are already excellent answers here that explain how to install ntpd so that your computer continuously keeps itself in sync with internet time servers, but I just wanted to add that by default Ubuntu will synchronize time with ntp.ubuntu.com whenever your network interface comes "up" (e.g. when you start your computer). This does not appear be happening in your case because of the way you connect to the internet, but other readers should not assume that Ubuntu does not sync time without ntpd being installed.

    – user8979
    Feb 27 '11 at 9:30











  • Here is one that explains how to set it to time.nist.gov: askubuntu.com/questions/972799/…

    – SDsolar
    Nov 4 '17 at 8:05














23












23








23


13






I would like Ubuntu to automatically synchronize my system clock with a timeserver at startup.



However, my PC isn't connected to the Internet until after I've logged in (plus 5 - 10 seconds for good measure).



How can I set it to do this?










share|improve this question
















I would like Ubuntu to automatically synchronize my system clock with a timeserver at startup.



However, my PC isn't connected to the Internet until after I've logged in (plus 5 - 10 seconds for good measure).



How can I set it to do this?







ntp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 13 '14 at 18:02









Braiam

51.8k20136221




51.8k20136221










asked Jul 29 '10 at 0:01









Nathan OsmanNathan Osman

20.9k32144237




20.9k32144237








  • 2





    There are already excellent answers here that explain how to install ntpd so that your computer continuously keeps itself in sync with internet time servers, but I just wanted to add that by default Ubuntu will synchronize time with ntp.ubuntu.com whenever your network interface comes "up" (e.g. when you start your computer). This does not appear be happening in your case because of the way you connect to the internet, but other readers should not assume that Ubuntu does not sync time without ntpd being installed.

    – user8979
    Feb 27 '11 at 9:30











  • Here is one that explains how to set it to time.nist.gov: askubuntu.com/questions/972799/…

    – SDsolar
    Nov 4 '17 at 8:05














  • 2





    There are already excellent answers here that explain how to install ntpd so that your computer continuously keeps itself in sync with internet time servers, but I just wanted to add that by default Ubuntu will synchronize time with ntp.ubuntu.com whenever your network interface comes "up" (e.g. when you start your computer). This does not appear be happening in your case because of the way you connect to the internet, but other readers should not assume that Ubuntu does not sync time without ntpd being installed.

    – user8979
    Feb 27 '11 at 9:30











  • Here is one that explains how to set it to time.nist.gov: askubuntu.com/questions/972799/…

    – SDsolar
    Nov 4 '17 at 8:05








2




2





There are already excellent answers here that explain how to install ntpd so that your computer continuously keeps itself in sync with internet time servers, but I just wanted to add that by default Ubuntu will synchronize time with ntp.ubuntu.com whenever your network interface comes "up" (e.g. when you start your computer). This does not appear be happening in your case because of the way you connect to the internet, but other readers should not assume that Ubuntu does not sync time without ntpd being installed.

– user8979
Feb 27 '11 at 9:30





There are already excellent answers here that explain how to install ntpd so that your computer continuously keeps itself in sync with internet time servers, but I just wanted to add that by default Ubuntu will synchronize time with ntp.ubuntu.com whenever your network interface comes "up" (e.g. when you start your computer). This does not appear be happening in your case because of the way you connect to the internet, but other readers should not assume that Ubuntu does not sync time without ntpd being installed.

– user8979
Feb 27 '11 at 9:30













Here is one that explains how to set it to time.nist.gov: askubuntu.com/questions/972799/…

– SDsolar
Nov 4 '17 at 8:05





Here is one that explains how to set it to time.nist.gov: askubuntu.com/questions/972799/…

– SDsolar
Nov 4 '17 at 8:05










4 Answers
4






active

oldest

votes


















31














This is done with NTP, for which instructions are available. Basically, you'll need to install an NTP daemon. There seem to be several choices available but the "standard" one is in the package ntp. According to the instructions at the linked page,



sudo apt-get install ntp


will get everything set up to synchronize with Ubuntu's NTP server.



EDIT: I missed "at startup." It's generally recommended to use ntpd to get continuous synchronization between your system and the server, but if you really only want to synchronize once, mfisch's answer seems to be what you're looking for.






share|improve this answer



















  • 3





    I think in general he'd be better off just having ntpd always running and just having it fail to connect when he was not online, that is by no means harmful. With that said, my method should also work ;)

    – mfisch
    Jul 29 '10 at 1:02











  • I'm okay with it running continuously.

    – Nathan Osman
    Jul 29 '10 at 1:35






  • 1





    George, just do that. I was hoping to answer your "real" question since the most annoying thing in the world is asking a question like this and having all the responses be "why do you want to do that?"

    – mfisch
    Jul 29 '10 at 2:01



















9














If you go to "System->Administration->Time and Date", you will get a GUI to set the date/time.



An option is provided for using time servers. If you check it and NTP is not installed, it will ask if you want to install it. Just click "yes", and let it do its job :)






share|improve this answer


























  • Forgot the "startup" thing. NTP does its job regularly, which means that you should get synchronized whenever you are online... But the only way to make sure is to use some kind of script as provided by mfisch. Now to be honest : once synchronized, there's little chance that your computer gets messed up on its clock. So if you use the default time synchronization, and let it do it in background, you should be good to go most of the time, without having to do anything more.

    – Little Jawa
    Jul 29 '10 at 8:50











  • Isn't it labeled "Time and Date"?

    – Firefeather
    Nov 8 '10 at 0:00











  • @Firefeather: it may well be. I don't have an english interface, so I can't tell ;)

    – Little Jawa
    Nov 8 '10 at 6:41











  • Ah, silly me, forgetting about the internationalization. My en-us system labels it "Time and Date".

    – Firefeather
    Nov 9 '10 at 4:39



















7














You can do this using at and ntpdate. at is probably already installed, but ntpdate may not be. (apt-get install ntpdate).



First create a small script that runs ntpdate, lets call it update_time.sh.



#!/bin/bash
ntpdate pool.ntp.org


In your .bash_login file (which you may need to create) add this:



at -f ~/update_time.sh now + 1 minute


That should do what you want. You can change the delay that at uses to be 5 minutes, 10 minutes etc.



EDIT: I just realized that you'll need to be root to run ntpdate. You'll need to set the SUID bit on the update_time.sh script that I mentioned. You can do that by running this from the command (only needs to be run once):



sudo chmod 4711 update_time.sh
sudo chown root update_time.sh





share|improve this answer





















  • 1





    iirc You can't set suid on .sh scripts.

    – Broam
    Jul 29 '10 at 1:03











  • Can you do the suid on ntpdate directly then? That would probably accomplish the same thing.

    – mfisch
    Jul 29 '10 at 2:00






  • 2





    Why use at? And if you're going to automatically run ntpdate, why not just install the ntp service?

    – Reinier Post
    Aug 27 '14 at 12:07













  • note: ntpdate is no longer installed by default on Ubuntu (16.04+) and was deprecated in favor of timedatectl. timedatectl controls systemd's timesyncd service, which is used by default for time synchronization.

    – Corey Goldberg
    Jun 10 '17 at 23:42





















0














Since Ubuntu 16.04 timedatectl / timesyncd (which are part of systemd) replace most of ntpdate / ntp. See Time Synchronization.



You might need to activate time synchronization using:



$ sudo timedatectl set-ntp on



If you want to use chrony:




  • If you require a one-shot sync use: $ chronyd -q


  • If you require a one-shot time check, without setting the time use: $ chronyd -Q


  • For continuous syncing, the recommended solution is chrony:




chrony(d)



The NTP daemon chronyd calculates the drift and offset of your system
clock and continuously adjusts it, so there are no large corrections
that could lead to inconsistent logs for instance. The cost is a
little processing power and memory, but for a modern server this is
usually negligible. Installation



To install chrony, from a terminal prompt enter:



$ sudo apt install chrony




You might also need to activate



sudo timedatectl set-ntp on



Update: Another method if the above doesn't work is to set a cron job to run $ chronyd -q






share|improve this answer

























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f228%2fhow-to-set-ubuntu-to-synchronize-my-clock-with-a-time-server%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    31














    This is done with NTP, for which instructions are available. Basically, you'll need to install an NTP daemon. There seem to be several choices available but the "standard" one is in the package ntp. According to the instructions at the linked page,



    sudo apt-get install ntp


    will get everything set up to synchronize with Ubuntu's NTP server.



    EDIT: I missed "at startup." It's generally recommended to use ntpd to get continuous synchronization between your system and the server, but if you really only want to synchronize once, mfisch's answer seems to be what you're looking for.






    share|improve this answer



















    • 3





      I think in general he'd be better off just having ntpd always running and just having it fail to connect when he was not online, that is by no means harmful. With that said, my method should also work ;)

      – mfisch
      Jul 29 '10 at 1:02











    • I'm okay with it running continuously.

      – Nathan Osman
      Jul 29 '10 at 1:35






    • 1





      George, just do that. I was hoping to answer your "real" question since the most annoying thing in the world is asking a question like this and having all the responses be "why do you want to do that?"

      – mfisch
      Jul 29 '10 at 2:01
















    31














    This is done with NTP, for which instructions are available. Basically, you'll need to install an NTP daemon. There seem to be several choices available but the "standard" one is in the package ntp. According to the instructions at the linked page,



    sudo apt-get install ntp


    will get everything set up to synchronize with Ubuntu's NTP server.



    EDIT: I missed "at startup." It's generally recommended to use ntpd to get continuous synchronization between your system and the server, but if you really only want to synchronize once, mfisch's answer seems to be what you're looking for.






    share|improve this answer



















    • 3





      I think in general he'd be better off just having ntpd always running and just having it fail to connect when he was not online, that is by no means harmful. With that said, my method should also work ;)

      – mfisch
      Jul 29 '10 at 1:02











    • I'm okay with it running continuously.

      – Nathan Osman
      Jul 29 '10 at 1:35






    • 1





      George, just do that. I was hoping to answer your "real" question since the most annoying thing in the world is asking a question like this and having all the responses be "why do you want to do that?"

      – mfisch
      Jul 29 '10 at 2:01














    31












    31








    31







    This is done with NTP, for which instructions are available. Basically, you'll need to install an NTP daemon. There seem to be several choices available but the "standard" one is in the package ntp. According to the instructions at the linked page,



    sudo apt-get install ntp


    will get everything set up to synchronize with Ubuntu's NTP server.



    EDIT: I missed "at startup." It's generally recommended to use ntpd to get continuous synchronization between your system and the server, but if you really only want to synchronize once, mfisch's answer seems to be what you're looking for.






    share|improve this answer













    This is done with NTP, for which instructions are available. Basically, you'll need to install an NTP daemon. There seem to be several choices available but the "standard" one is in the package ntp. According to the instructions at the linked page,



    sudo apt-get install ntp


    will get everything set up to synchronize with Ubuntu's NTP server.



    EDIT: I missed "at startup." It's generally recommended to use ntpd to get continuous synchronization between your system and the server, but if you really only want to synchronize once, mfisch's answer seems to be what you're looking for.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jul 29 '10 at 0:57









    David ZDavid Z

    3,78352021




    3,78352021








    • 3





      I think in general he'd be better off just having ntpd always running and just having it fail to connect when he was not online, that is by no means harmful. With that said, my method should also work ;)

      – mfisch
      Jul 29 '10 at 1:02











    • I'm okay with it running continuously.

      – Nathan Osman
      Jul 29 '10 at 1:35






    • 1





      George, just do that. I was hoping to answer your "real" question since the most annoying thing in the world is asking a question like this and having all the responses be "why do you want to do that?"

      – mfisch
      Jul 29 '10 at 2:01














    • 3





      I think in general he'd be better off just having ntpd always running and just having it fail to connect when he was not online, that is by no means harmful. With that said, my method should also work ;)

      – mfisch
      Jul 29 '10 at 1:02











    • I'm okay with it running continuously.

      – Nathan Osman
      Jul 29 '10 at 1:35






    • 1





      George, just do that. I was hoping to answer your "real" question since the most annoying thing in the world is asking a question like this and having all the responses be "why do you want to do that?"

      – mfisch
      Jul 29 '10 at 2:01








    3




    3





    I think in general he'd be better off just having ntpd always running and just having it fail to connect when he was not online, that is by no means harmful. With that said, my method should also work ;)

    – mfisch
    Jul 29 '10 at 1:02





    I think in general he'd be better off just having ntpd always running and just having it fail to connect when he was not online, that is by no means harmful. With that said, my method should also work ;)

    – mfisch
    Jul 29 '10 at 1:02













    I'm okay with it running continuously.

    – Nathan Osman
    Jul 29 '10 at 1:35





    I'm okay with it running continuously.

    – Nathan Osman
    Jul 29 '10 at 1:35




    1




    1





    George, just do that. I was hoping to answer your "real" question since the most annoying thing in the world is asking a question like this and having all the responses be "why do you want to do that?"

    – mfisch
    Jul 29 '10 at 2:01





    George, just do that. I was hoping to answer your "real" question since the most annoying thing in the world is asking a question like this and having all the responses be "why do you want to do that?"

    – mfisch
    Jul 29 '10 at 2:01













    9














    If you go to "System->Administration->Time and Date", you will get a GUI to set the date/time.



    An option is provided for using time servers. If you check it and NTP is not installed, it will ask if you want to install it. Just click "yes", and let it do its job :)






    share|improve this answer


























    • Forgot the "startup" thing. NTP does its job regularly, which means that you should get synchronized whenever you are online... But the only way to make sure is to use some kind of script as provided by mfisch. Now to be honest : once synchronized, there's little chance that your computer gets messed up on its clock. So if you use the default time synchronization, and let it do it in background, you should be good to go most of the time, without having to do anything more.

      – Little Jawa
      Jul 29 '10 at 8:50











    • Isn't it labeled "Time and Date"?

      – Firefeather
      Nov 8 '10 at 0:00











    • @Firefeather: it may well be. I don't have an english interface, so I can't tell ;)

      – Little Jawa
      Nov 8 '10 at 6:41











    • Ah, silly me, forgetting about the internationalization. My en-us system labels it "Time and Date".

      – Firefeather
      Nov 9 '10 at 4:39
















    9














    If you go to "System->Administration->Time and Date", you will get a GUI to set the date/time.



    An option is provided for using time servers. If you check it and NTP is not installed, it will ask if you want to install it. Just click "yes", and let it do its job :)






    share|improve this answer


























    • Forgot the "startup" thing. NTP does its job regularly, which means that you should get synchronized whenever you are online... But the only way to make sure is to use some kind of script as provided by mfisch. Now to be honest : once synchronized, there's little chance that your computer gets messed up on its clock. So if you use the default time synchronization, and let it do it in background, you should be good to go most of the time, without having to do anything more.

      – Little Jawa
      Jul 29 '10 at 8:50











    • Isn't it labeled "Time and Date"?

      – Firefeather
      Nov 8 '10 at 0:00











    • @Firefeather: it may well be. I don't have an english interface, so I can't tell ;)

      – Little Jawa
      Nov 8 '10 at 6:41











    • Ah, silly me, forgetting about the internationalization. My en-us system labels it "Time and Date".

      – Firefeather
      Nov 9 '10 at 4:39














    9












    9








    9







    If you go to "System->Administration->Time and Date", you will get a GUI to set the date/time.



    An option is provided for using time servers. If you check it and NTP is not installed, it will ask if you want to install it. Just click "yes", and let it do its job :)






    share|improve this answer















    If you go to "System->Administration->Time and Date", you will get a GUI to set the date/time.



    An option is provided for using time servers. If you check it and NTP is not installed, it will ask if you want to install it. Just click "yes", and let it do its job :)







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 10 '10 at 6:48

























    answered Jul 29 '10 at 8:46









    Little JawaLittle Jawa

    2,28321525




    2,28321525













    • Forgot the "startup" thing. NTP does its job regularly, which means that you should get synchronized whenever you are online... But the only way to make sure is to use some kind of script as provided by mfisch. Now to be honest : once synchronized, there's little chance that your computer gets messed up on its clock. So if you use the default time synchronization, and let it do it in background, you should be good to go most of the time, without having to do anything more.

      – Little Jawa
      Jul 29 '10 at 8:50











    • Isn't it labeled "Time and Date"?

      – Firefeather
      Nov 8 '10 at 0:00











    • @Firefeather: it may well be. I don't have an english interface, so I can't tell ;)

      – Little Jawa
      Nov 8 '10 at 6:41











    • Ah, silly me, forgetting about the internationalization. My en-us system labels it "Time and Date".

      – Firefeather
      Nov 9 '10 at 4:39



















    • Forgot the "startup" thing. NTP does its job regularly, which means that you should get synchronized whenever you are online... But the only way to make sure is to use some kind of script as provided by mfisch. Now to be honest : once synchronized, there's little chance that your computer gets messed up on its clock. So if you use the default time synchronization, and let it do it in background, you should be good to go most of the time, without having to do anything more.

      – Little Jawa
      Jul 29 '10 at 8:50











    • Isn't it labeled "Time and Date"?

      – Firefeather
      Nov 8 '10 at 0:00











    • @Firefeather: it may well be. I don't have an english interface, so I can't tell ;)

      – Little Jawa
      Nov 8 '10 at 6:41











    • Ah, silly me, forgetting about the internationalization. My en-us system labels it "Time and Date".

      – Firefeather
      Nov 9 '10 at 4:39

















    Forgot the "startup" thing. NTP does its job regularly, which means that you should get synchronized whenever you are online... But the only way to make sure is to use some kind of script as provided by mfisch. Now to be honest : once synchronized, there's little chance that your computer gets messed up on its clock. So if you use the default time synchronization, and let it do it in background, you should be good to go most of the time, without having to do anything more.

    – Little Jawa
    Jul 29 '10 at 8:50





    Forgot the "startup" thing. NTP does its job regularly, which means that you should get synchronized whenever you are online... But the only way to make sure is to use some kind of script as provided by mfisch. Now to be honest : once synchronized, there's little chance that your computer gets messed up on its clock. So if you use the default time synchronization, and let it do it in background, you should be good to go most of the time, without having to do anything more.

    – Little Jawa
    Jul 29 '10 at 8:50













    Isn't it labeled "Time and Date"?

    – Firefeather
    Nov 8 '10 at 0:00





    Isn't it labeled "Time and Date"?

    – Firefeather
    Nov 8 '10 at 0:00













    @Firefeather: it may well be. I don't have an english interface, so I can't tell ;)

    – Little Jawa
    Nov 8 '10 at 6:41





    @Firefeather: it may well be. I don't have an english interface, so I can't tell ;)

    – Little Jawa
    Nov 8 '10 at 6:41













    Ah, silly me, forgetting about the internationalization. My en-us system labels it "Time and Date".

    – Firefeather
    Nov 9 '10 at 4:39





    Ah, silly me, forgetting about the internationalization. My en-us system labels it "Time and Date".

    – Firefeather
    Nov 9 '10 at 4:39











    7














    You can do this using at and ntpdate. at is probably already installed, but ntpdate may not be. (apt-get install ntpdate).



    First create a small script that runs ntpdate, lets call it update_time.sh.



    #!/bin/bash
    ntpdate pool.ntp.org


    In your .bash_login file (which you may need to create) add this:



    at -f ~/update_time.sh now + 1 minute


    That should do what you want. You can change the delay that at uses to be 5 minutes, 10 minutes etc.



    EDIT: I just realized that you'll need to be root to run ntpdate. You'll need to set the SUID bit on the update_time.sh script that I mentioned. You can do that by running this from the command (only needs to be run once):



    sudo chmod 4711 update_time.sh
    sudo chown root update_time.sh





    share|improve this answer





















    • 1





      iirc You can't set suid on .sh scripts.

      – Broam
      Jul 29 '10 at 1:03











    • Can you do the suid on ntpdate directly then? That would probably accomplish the same thing.

      – mfisch
      Jul 29 '10 at 2:00






    • 2





      Why use at? And if you're going to automatically run ntpdate, why not just install the ntp service?

      – Reinier Post
      Aug 27 '14 at 12:07













    • note: ntpdate is no longer installed by default on Ubuntu (16.04+) and was deprecated in favor of timedatectl. timedatectl controls systemd's timesyncd service, which is used by default for time synchronization.

      – Corey Goldberg
      Jun 10 '17 at 23:42


















    7














    You can do this using at and ntpdate. at is probably already installed, but ntpdate may not be. (apt-get install ntpdate).



    First create a small script that runs ntpdate, lets call it update_time.sh.



    #!/bin/bash
    ntpdate pool.ntp.org


    In your .bash_login file (which you may need to create) add this:



    at -f ~/update_time.sh now + 1 minute


    That should do what you want. You can change the delay that at uses to be 5 minutes, 10 minutes etc.



    EDIT: I just realized that you'll need to be root to run ntpdate. You'll need to set the SUID bit on the update_time.sh script that I mentioned. You can do that by running this from the command (only needs to be run once):



    sudo chmod 4711 update_time.sh
    sudo chown root update_time.sh





    share|improve this answer





















    • 1





      iirc You can't set suid on .sh scripts.

      – Broam
      Jul 29 '10 at 1:03











    • Can you do the suid on ntpdate directly then? That would probably accomplish the same thing.

      – mfisch
      Jul 29 '10 at 2:00






    • 2





      Why use at? And if you're going to automatically run ntpdate, why not just install the ntp service?

      – Reinier Post
      Aug 27 '14 at 12:07













    • note: ntpdate is no longer installed by default on Ubuntu (16.04+) and was deprecated in favor of timedatectl. timedatectl controls systemd's timesyncd service, which is used by default for time synchronization.

      – Corey Goldberg
      Jun 10 '17 at 23:42
















    7












    7








    7







    You can do this using at and ntpdate. at is probably already installed, but ntpdate may not be. (apt-get install ntpdate).



    First create a small script that runs ntpdate, lets call it update_time.sh.



    #!/bin/bash
    ntpdate pool.ntp.org


    In your .bash_login file (which you may need to create) add this:



    at -f ~/update_time.sh now + 1 minute


    That should do what you want. You can change the delay that at uses to be 5 minutes, 10 minutes etc.



    EDIT: I just realized that you'll need to be root to run ntpdate. You'll need to set the SUID bit on the update_time.sh script that I mentioned. You can do that by running this from the command (only needs to be run once):



    sudo chmod 4711 update_time.sh
    sudo chown root update_time.sh





    share|improve this answer















    You can do this using at and ntpdate. at is probably already installed, but ntpdate may not be. (apt-get install ntpdate).



    First create a small script that runs ntpdate, lets call it update_time.sh.



    #!/bin/bash
    ntpdate pool.ntp.org


    In your .bash_login file (which you may need to create) add this:



    at -f ~/update_time.sh now + 1 minute


    That should do what you want. You can change the delay that at uses to be 5 minutes, 10 minutes etc.



    EDIT: I just realized that you'll need to be root to run ntpdate. You'll need to set the SUID bit on the update_time.sh script that I mentioned. You can do that by running this from the command (only needs to be run once):



    sudo chmod 4711 update_time.sh
    sudo chown root update_time.sh






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 7 '13 at 12:02









    Indian

    84231836




    84231836










    answered Jul 29 '10 at 0:57









    mfischmfisch

    2,68712138




    2,68712138








    • 1





      iirc You can't set suid on .sh scripts.

      – Broam
      Jul 29 '10 at 1:03











    • Can you do the suid on ntpdate directly then? That would probably accomplish the same thing.

      – mfisch
      Jul 29 '10 at 2:00






    • 2





      Why use at? And if you're going to automatically run ntpdate, why not just install the ntp service?

      – Reinier Post
      Aug 27 '14 at 12:07













    • note: ntpdate is no longer installed by default on Ubuntu (16.04+) and was deprecated in favor of timedatectl. timedatectl controls systemd's timesyncd service, which is used by default for time synchronization.

      – Corey Goldberg
      Jun 10 '17 at 23:42
















    • 1





      iirc You can't set suid on .sh scripts.

      – Broam
      Jul 29 '10 at 1:03











    • Can you do the suid on ntpdate directly then? That would probably accomplish the same thing.

      – mfisch
      Jul 29 '10 at 2:00






    • 2





      Why use at? And if you're going to automatically run ntpdate, why not just install the ntp service?

      – Reinier Post
      Aug 27 '14 at 12:07













    • note: ntpdate is no longer installed by default on Ubuntu (16.04+) and was deprecated in favor of timedatectl. timedatectl controls systemd's timesyncd service, which is used by default for time synchronization.

      – Corey Goldberg
      Jun 10 '17 at 23:42










    1




    1





    iirc You can't set suid on .sh scripts.

    – Broam
    Jul 29 '10 at 1:03





    iirc You can't set suid on .sh scripts.

    – Broam
    Jul 29 '10 at 1:03













    Can you do the suid on ntpdate directly then? That would probably accomplish the same thing.

    – mfisch
    Jul 29 '10 at 2:00





    Can you do the suid on ntpdate directly then? That would probably accomplish the same thing.

    – mfisch
    Jul 29 '10 at 2:00




    2




    2





    Why use at? And if you're going to automatically run ntpdate, why not just install the ntp service?

    – Reinier Post
    Aug 27 '14 at 12:07







    Why use at? And if you're going to automatically run ntpdate, why not just install the ntp service?

    – Reinier Post
    Aug 27 '14 at 12:07















    note: ntpdate is no longer installed by default on Ubuntu (16.04+) and was deprecated in favor of timedatectl. timedatectl controls systemd's timesyncd service, which is used by default for time synchronization.

    – Corey Goldberg
    Jun 10 '17 at 23:42







    note: ntpdate is no longer installed by default on Ubuntu (16.04+) and was deprecated in favor of timedatectl. timedatectl controls systemd's timesyncd service, which is used by default for time synchronization.

    – Corey Goldberg
    Jun 10 '17 at 23:42













    0














    Since Ubuntu 16.04 timedatectl / timesyncd (which are part of systemd) replace most of ntpdate / ntp. See Time Synchronization.



    You might need to activate time synchronization using:



    $ sudo timedatectl set-ntp on



    If you want to use chrony:




    • If you require a one-shot sync use: $ chronyd -q


    • If you require a one-shot time check, without setting the time use: $ chronyd -Q


    • For continuous syncing, the recommended solution is chrony:




    chrony(d)



    The NTP daemon chronyd calculates the drift and offset of your system
    clock and continuously adjusts it, so there are no large corrections
    that could lead to inconsistent logs for instance. The cost is a
    little processing power and memory, but for a modern server this is
    usually negligible. Installation



    To install chrony, from a terminal prompt enter:



    $ sudo apt install chrony




    You might also need to activate



    sudo timedatectl set-ntp on



    Update: Another method if the above doesn't work is to set a cron job to run $ chronyd -q






    share|improve this answer






























      0














      Since Ubuntu 16.04 timedatectl / timesyncd (which are part of systemd) replace most of ntpdate / ntp. See Time Synchronization.



      You might need to activate time synchronization using:



      $ sudo timedatectl set-ntp on



      If you want to use chrony:




      • If you require a one-shot sync use: $ chronyd -q


      • If you require a one-shot time check, without setting the time use: $ chronyd -Q


      • For continuous syncing, the recommended solution is chrony:




      chrony(d)



      The NTP daemon chronyd calculates the drift and offset of your system
      clock and continuously adjusts it, so there are no large corrections
      that could lead to inconsistent logs for instance. The cost is a
      little processing power and memory, but for a modern server this is
      usually negligible. Installation



      To install chrony, from a terminal prompt enter:



      $ sudo apt install chrony




      You might also need to activate



      sudo timedatectl set-ntp on



      Update: Another method if the above doesn't work is to set a cron job to run $ chronyd -q






      share|improve this answer




























        0












        0








        0







        Since Ubuntu 16.04 timedatectl / timesyncd (which are part of systemd) replace most of ntpdate / ntp. See Time Synchronization.



        You might need to activate time synchronization using:



        $ sudo timedatectl set-ntp on



        If you want to use chrony:




        • If you require a one-shot sync use: $ chronyd -q


        • If you require a one-shot time check, without setting the time use: $ chronyd -Q


        • For continuous syncing, the recommended solution is chrony:




        chrony(d)



        The NTP daemon chronyd calculates the drift and offset of your system
        clock and continuously adjusts it, so there are no large corrections
        that could lead to inconsistent logs for instance. The cost is a
        little processing power and memory, but for a modern server this is
        usually negligible. Installation



        To install chrony, from a terminal prompt enter:



        $ sudo apt install chrony




        You might also need to activate



        sudo timedatectl set-ntp on



        Update: Another method if the above doesn't work is to set a cron job to run $ chronyd -q






        share|improve this answer















        Since Ubuntu 16.04 timedatectl / timesyncd (which are part of systemd) replace most of ntpdate / ntp. See Time Synchronization.



        You might need to activate time synchronization using:



        $ sudo timedatectl set-ntp on



        If you want to use chrony:




        • If you require a one-shot sync use: $ chronyd -q


        • If you require a one-shot time check, without setting the time use: $ chronyd -Q


        • For continuous syncing, the recommended solution is chrony:




        chrony(d)



        The NTP daemon chronyd calculates the drift and offset of your system
        clock and continuously adjusts it, so there are no large corrections
        that could lead to inconsistent logs for instance. The cost is a
        little processing power and memory, but for a modern server this is
        usually negligible. Installation



        To install chrony, from a terminal prompt enter:



        $ sudo apt install chrony




        You might also need to activate



        sudo timedatectl set-ntp on



        Update: Another method if the above doesn't work is to set a cron job to run $ chronyd -q







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 2 days ago

























        answered Oct 18 '18 at 13:55









        JBaczukJBaczuk

        19818




        19818






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f228%2fhow-to-set-ubuntu-to-synchronize-my-clock-with-a-time-server%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            數位音樂下載

            When can things happen in Etherscan, such as the picture below?

            格利澤436b