Changing system time using /bin/date Changing system time using /bin/date shell shell

Changing system time using /bin/date


After editing a /etc/sudoers, do a

 sudo date -s

command. This will do the actual date command from "Root" user.

Just edit of /etc/sudoers is not enough, because it will not give a root to user, but it will give a capability to became root from user using sudo utility.


type

sudo visudo

add the next command

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

or

<username> ALL=(ALL) NOPASSWD: /usr/bin/timedatectl

now you can edit your time from the specific account without password like

sudo timedatectl set-time <datetime>


Also should note that line

Default requiretty

should becommented in sudoers file. Otherwise you will get a message to STDERR, saying

sudo: sorry, you must have a tty to run sudo

when trying to invoke the script from outer world.

This was a problem in my case.