17

I'm running Ubuntu in a VM. How do I disable ntpd?

muru
  • 197,895
  • 55
  • 485
  • 740

3 Answers3

18

To stop ntpd:

sudo /etc/init.d/ntp stop

or

sudo service ntp stop

To prevent it from starting at boot:

sudo update-rc.d -f ntp remove
8

With systemd, the two commands are:

sudo systemctl stop ntp
sudo systemctl disable ntp

Output (I think the warning can be ignored)

ntp.service is not a native service, redirecting to systemd-sysv-install
Executing /lib/systemd/systemd-sysv-install disable ntp
insserv: warning: current start runlevel(s) (empty) of script `ntp' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (1 2 3 4 5) of script `ntp' overrides LSB defaults (1).
insserv: warning: current start runlevel(s) (empty) of script `ntp' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (1 2 3 4 5) of script `ntp' overrides LSB defaults (1).

Check:

systemctl is-enabled ntp

Output

ntp.service is not a native service, redirecting to systemd-sysv-install
Executing /lib/systemd/systemd-sysv-install is-enabled ntp
disabled
knb
  • 5,004
5

Uninstall ntpd if it is installed. You will still have ntpdate installed. (It is difficult to remove.) Prevent it from executing by adding exit 0 to /etc/default/ntpdate.

Update: This is an old answer. Most systems now use systemctl to run commands. To disable ntp and ntpdate issue the commands:

systemctl disable ntp.service 
systemctl disable ntpdate.service 

You can check the status of ntp related units with the command:

 systemctl list-unit-files | grep ntp    
BillThor
  • 4,698
  • Are you sure about this? /etc/default/ntpdate is just a configuration file. Dunno if it is sourced by any bash script, but I guess it's useless to add exit. – Gelma Mar 04 '21 at 10:02
  • @Gelma files in /etc/default are usually sourced by the script running the related command. This was always the case for commands run by init.d scripts. Commands run by systemctl may not source the file. See update for the systemctl option. – BillThor Mar 09 '21 at 17:50