use sudo without password in QProcess



  • I would like the user to be able to change the timezone and can be done so with the following commands:

    $ sudo unlink /etc/localtime 
    $ sudo ln -s /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
    

    I would like to use QProcess but the commands require sudo and I don't want the user to enter passwords. I researched and found that you can enter the following under /etc/sudoers:

    user = (root) NOPASSWD: command
    

    However, I believe the command has to be the exact one the user would like to use and to change the timezone, it will not always be "America/Los_Angeles." Is there a way to make it work with QProcess so that the user doesn't have to enter a password by using sudo? I also do not want to have a password to be saved.



  • Hi @marlenet15,

    I believe the command has to be the exact one the user would like to use

    Not so :)

    http://linux.die.net/man/5/sudoers says:

    A simple file name allows the user to run the command with any arguments he/she wishes. However, you may also specify command line arguments (including wildcards). Alternately, you can specify "" to indicate that the command may only be run without command line arguments.

    So you should be able to do something like:

    user ALL=(root) NOPASSWD: ln -s /usr/share/zoneinfo/*/* /etc/localtime
    

    Of course you should always be careful with sudoers, but even more so when using wildcards.

    Cheers.


  • Qt Champions 2016

    @marlenet15

    @Paul-Colby said:

    Of course you should always be careful with sudoers, but even more so when using wildcards.

    That's good advice and only to throw my 2 cents in:
    Allowing users to change system-wide settings somehow defeats the whole point of having users in the first place. What happens if one user changes the timezone, but another is not happy with that and changes it back? These are system changes we're talking about, so that's one good reason for actually having a super user that manages them ...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.