Changing date on Ubuntu without sudo privilages

1

I am trying to automate a time change on Ubuntu 10.04 with a bash script using the date command. The script works, but it requires sudo privileges, however, the user who will execute the script does not have sudo privileges. Obviously I do not want to include the sudo password in the script.

Is there file I can change the permissions of that would allow non sudo users to change the time?

Jake

Posted 2014-12-17T15:48:13.997

Reputation: 113

You could make a specific sudo exception: https://unix.stackexchange.com/questions/44865 (of course, replace apache with tthe username). This will give the user sudo privileges, but only for that specific command, and won't require sharing the password.

– Wander Nauta – 2014-12-17T15:51:36.493

Answers

3

You can add a line to the /etc/sudoers file.

This file controls who is allowed to run what commands using sudo, and whether they need to enter a password. A line similar to the below will do the trick, replacing <username> with the user's name:

<username> ALL=(ALL) NOPASSWD: /bin/date

You can also use a group name using %groupname format.

Edit this file using the visudo command, which you will need to run as root, with sudo.

You can find much more info in the sudoers man page (man sudoers) or in the Ubuntu documentation at https://help.ubuntu.com/community/Sudoers

stonecrusher

Posted 2014-12-17T15:48:13.997

Reputation: 261

1

I solved this problem using libfaketime, and it worked very well. This is definitely more secure than allowing anyone to change the date on your computer.

ostrokach

Posted 2014-12-17T15:48:13.997

Reputation: 475