Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On my Ubuntu 10.04 box I (a user, not root) can issue

sudo net time set

and it works great.

I'd prefer that the box get the net time on a more regular basis, or at least each time it gets logged in. So, I tried adding net time set to /etc/profile. That fails. I added stanzas that look like

user ALL=(ALL) NOPASSWD: /usr/bin/net

to /etc/sudoers (using visudo). Didn't help.

I have never touched cron so I have no idea how to add a chron tab. (does seem oxymoronic to depend on the system time to reset the system time.)

  1. What is the best way to do this?
  2. If it's a cron job, I'd appreciate a quick example.
  3. Same questions but for the command service dhcp3-server restart?

(yes, my box gets its address by dhcp, but its dhcp server controls 4 gigabit enet cards attached to high speed cameras. Sometimes, at login? bootup? the dhcp server leaves me seeing only 1 camera.)

Thanks in advance.

share|improve this question

migrated from Jan 11 '12 at 13:24

This question came from our site for professional and enthusiast programmers.

up vote 1 down vote accepted

(Yes, I'm adding a second answer.)

From your description, you've added the appropriate line to /etc/sudoers, but you're not invoking sudo in /etc/profile.

The command in /etc/profile needs to be:

sudo net time set

Note that this will run every time any account logs in. Is that what you want, or would it make more sense to put the command in $HOME/.profile?

To make it a cron job, you can add something like this:

0 * * * * *      sudo net time set

to, say, foo.txt, then crontab foo.txt. After that, crontab -l will show you your current cron job(s). With the given parameters, the job will run once an hour; man 5 crontab and adjust as needed. There might be some issues because cron jobs run with a minimal environment, but I don't think /usr/bin/net depends on any environment variables.

Note that, unlike ntpd, this can cause your system's clock to jump backwards, which can cause problems.

share|improve this answer
Finally, I have an NTP server address I can use! So, can you give me a bit of guidance on NTPD? Thank you Keith! – Wes Miller Jan 12 '12 at 12:22
@WesMiller: I've updated my other answer, which now seems to be the more relevant one. – Keith Thompson Jan 12 '12 at 21:19
@WesMiller: Isn't my other answer the actual solution that you're using? – Keith Thompson Jan 12 '12 at 22:49

Don't bother.

The usual way to keep the system clock synchronized is ntpd. It should be installed and configured by default on Ubuntu. Do you have an ntpd process running? Is your system's clock incorrect?


From your comment on my other answer, it looks like you've got an NTP server you can use.

You should already have the ntp software installed on your system. dpkg -l ntp to verify. You probably have an ntpd daemon already running, though it won't work because it doesn't know what server to talk to; ps -ef | grep ntpd to confirm that.

/etc/ntp.conf is the configuration file for ntp. The default version has:


Comment out those lines and add:

server your.ntp.server

then run:

sudo /etc/init.d ntp restart

man ntpd for more details, but this should be enough to get you going.

share|improve this answer
My system clock was incorrect. Running a net time set once seemed to fix it. Interestingly enough, the man for net says I have to identify the ntp server. I didn't, but it still seemed to work. Wonder why. Anyway, apparently ntpd is not on my machine and is not running. I'm in my clients VPN and can't connect out of it to anyuthing but my remote desktop. Unless I can get a package that I can cp onto the machine, I'm out of luck. – Wes Miller Jan 11 '12 at 12:39
Ok, then if you can't connect to anything but your remote desktop then ntpd isn't going to be able to talk to an NTP server, unless you can set up such a server on your remote desktop. (ntpd is the right solution for most circumstances, though.) – Keith Thompson Jan 11 '12 at 23:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.