Search code examples
linuxcronsudocentos7ntp

NTP permission issue


I gave everyone in my team a copy of a centos 7 virtual machine. The time can get out of sync. I found that I can manually update the time by using the command below:

[no_sudo@rolling ~]$ ntpdate pool.ntp.org
26 Apr 18:10:11 ntpdate[25928]: bind() fails: Permission denied
[no_sudo@rolling ~]$

However I can only update it as sudo. One of the commands I made for the team runs some automated testing, and uses the date.time as a name.

How can I ether automate the updating of time on the virtual machine, or alter the permissions of that service, so anyone can run it regardless or permissions.

Thanks!


Solution

  • "How can I ether automate the updating of time on the virtual machine"

    The ntp daemon, ntpd, should take care of this. Sure it's running?

    # start the ntp daemon
    /etc/init.d/ntpd start
    

    You could also add a daily or hourly entry in root's crontab that updates the time:

    # To edit root's crontab
    sudo crontab -e
    # Add this line to run the command every day at noon (change as needed):
    * 12 * * * /usr/sbin/ntpdate
    

    "alter the permissions of that service, so anyone can run it"

    This undermines the security model. However, if the users are allowed to use sudo already, you could allow password-less execution of that single executable so it won't block your script:

    # To edit the sudoers file:
    sudo visudo
    # Then add something like this depending on the location of ntpdate:
    username ALL= NOPASSWD: /usr/sbin/ntpdate