How to change the date without being root?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to change the date without being root?

Jump to solution
3,478 Views
sandratrujillog
Contributor III

I use the development board T2080RDB-PC with Yocto QorIQSDK_v2.0. I have created users with restricted privileges using the useradd recipe. 

The problem is that for an application that I am developing I need to change the time often. How can these non-root users change the time? I just want these users to be able to change the date but remain users with restricted privileges.

Thanks.

0 Kudos
1 Solution
2,985 Views
yipingwang
NXP TechSupport
NXP TechSupport

Hello Sandra Trujillo García,

Please add "sudo" in the rootfs package list, then modify date with sudo permission on the target board.

You also could use the command "setcap CAP_SYS_TIME+ep /bin/date", please add libcap into rootfs filesystem.

You could refer to permissions - Allow a specific user or group root access without password to /bin/date - Unix & Linu... for details.


Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

3 Replies
2,986 Views
yipingwang
NXP TechSupport
NXP TechSupport

Hello Sandra Trujillo García,

Please add "sudo" in the rootfs package list, then modify date with sudo permission on the target board.

You also could use the command "setcap CAP_SYS_TIME+ep /bin/date", please add libcap into rootfs filesystem.

You could refer to permissions - Allow a specific user or group root access without password to /bin/date - Unix & Linu... for details.


Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

2,985 Views
sandratrujillog
Contributor III

I have managed to use the 'date' command without having to be a root user and without the need to enter the root password.
To do this we introduce the following command as root: # sudo visudo
Now the sudoers file will be opened and we will have to add the following line:

## My rules
Cmnd_Alias DATE = / bin / date
% group_name ALL = (root) NOPASSWD: DATE

Where group_name is the name of the group to which we want to give this permission, to know this name type the command 'groups' and the name of the user to whom you want to give permission

0 Kudos
2,985 Views
sandratrujillog
Contributor III

I'm trying to use the capabilities (CAP_SYS_TIME) but when I run the "setcap CAP_SYS_TIME + ep / bin / date" command, I get the following error:

Failed to set capabilities on file '/bin/date' (Invalid argument)

usage: setcap [-q] [-v] (-r|-|<caps>) <filename> [ ... (-r|-|<capsN>) <filenameN> ]

   Note <filename> must be a regular (non-symlink) file.

Any suggestions?

0 Kudos