1

How to make a non root user to view the hardware time other than hwclock command in centos 7

My requirement is to make a non root user to view the time alone

0

1 Answer 1

4

One could setup a sudo rule to allow the execution of hwclock without any arguments:

%sudo ALL=(ALL) NOPASSWD: /sbin/hwclock ""

Or grant read access to the RTC character device:

 $ groups johnny sudo staff $ sudo setfacl -m g:sudo:r /dev/rtc $ /sbin/hwclock Sun 18 Dec 2016 03:16:37 PM PST -0.318689 seconds 

This may have to be set after every reboot, as /dev is most likely volatile these days. I suppose an udev rule could handle this too.

In newer systemd-based systems, the timedatectl command is able to get the hardware clock w/o special permissions:

 $ timedatectl | head -3 Local time: Sun 2016-12-18 15:43:08 PST Universal time: Sun 2016-12-18 23:43:08 UTC RTC time: Sun 2016-12-18 23:43:08 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.