Thursday, February 6, 2020

Does anyone really know what time it is? service ntpd status - only root can check this? (chmod 700 vs 711 vs 755)

One of my FreeBSD 12 servers did not let me check if ntpd was running unless I was root, other ones were just fine with me being non-root user.

#NOT WORKING

root@server1:~ # chmod 700 /var/db/ntp
root@server1:~ # exit
logout
[me@server1 ~]$ service ntpd status
ntpd is not running.

[me@server1 ~]$ ps axww | grep ntpd
90506  -  Ss       0:01.66 /usr/sbin/ntpd -g -f /var/db/ntp/ntpd.drift -s /var/db/ntp -p /var/db/ntp/ntpd.pid -c /etc/ntp.conf -g
16563 12  S+       0:00.00 grep ntpd
[me@server1 ~]$ cat /var/db/ntp/ntpd.pid
cat: /var/db/ntp/ntpd.pid: Permission denied

#WORKING - HOW TO FIX

[me@server1 ~]$ sudo -i
root@server1:~ # chmod 711 /var/db/ntp
root@server1:~ # ls -lag /var/db/ntp/ntpd.pid
-rw-r--r--  1 ntpd  ntpd  5 Feb  5 22:04 /var/db/ntp/ntpd.pid
root@server1:~ # cat /var/db/ntp/ntpd.pid ; echo
90506
root@server1:~ # exit
logout
[me@server1 ~]$ service ntpd status
ntpd is running as pid 90506.
[me@server1 ~]$ uname -a
FreeBSD server1 12.0-RELEASE-p13 FreeBSD 12.0-RELEASE-p13 GENERIC  amd64

#WORKING
#Running ` service ntpd status ` as non-root user successfully.

[me@server2 ~]$ ls -lagd /var/db/ntp
drwxr-xr-x  2 ntpd  ntpd  4 Feb  6 09:35 /var/db/ntp
[me@server2 ~] service ntpd status
ntpd is running as pid 94795.

#Not working ` ls -lagd /var/db/ntp. `
drwx------  2 ntpd  ntpd  4 Feb  6 10:39 /var/db/ntp

#FreeBSD needs at least 711 for file protections to have status work
drwxr-xr-x  2 ntpd  ntpd  4 Feb  6 09:35 /var/db/ntp

#to have this work, but other servers are already set to 755
drwxr-xr-x  2 ntpd  ntpd  4 Feb  6 09:35 /var/db/ntp

No comments:

Post a Comment

Solve your own problems! - rubber duck problem solving

If you get stuck on an issue, googling the answer is not the only way to solve the problem.   Get yourself a rubber duck, use a cardboard...