Monday, November 16, 2020

How to enable regular user to set the Ubuntu system date as root without a password

I wanted to use the the time from a GPS to set the Ubuntu operating system date and time in an automated script; and I don't want the script to be interrupted with a prompt for an administrator password. So I tried to configure the sudoers configuration file to allow the group my user name belongs to to run the /bin/date command as root without a password. 

 For a long frustrating time, no matter what I configured, the date command would still prompt me for a password. Eventually, I got it working by doing the following: 

  1. Open up a Terminal and type in the commands to create my own configuration file.

    $ sudo visudo -f /etc/sudoers.d/10-override-date



  2. In the text editor, type in the following:

    %dialout ALL=NOPASSWD: /bin/date



    Note: dialout is the group I wanted to assign the ability to run date as root without a password.

  3. Save and exit.

  4. Subsequently, using the date command as any user in the dialout group would be executed successfully without a password prompt, as shown below.



No comments:

Post a Comment