How to change the date without being root?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

How to change the date without being root?

跳至解决方案
4,985 次查看
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 项奖励
回复
1 解答
4,492 次查看
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!
-----------------------------------------------------------------------------------------------------------------------

在原帖中查看解决方案

3 回复数
4,493 次查看
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!
-----------------------------------------------------------------------------------------------------------------------

4,492 次查看
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 项奖励
回复
4,492 次查看
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 项奖励
回复