Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. use sudo without password in QProcess
Forum Updated to NodeBB v4.3 + New Features

use sudo without password in QProcess

Scheduled Pinned Locked Moved Solved General and Desktop
qprocesssudolinux
3 Posts 3 Posters 3.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    marlenet15
    wrote on 27 Apr 2016, 18:42 last edited by
    #1

    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.

    1 Reply Last reply
    1
    • P Offline
      P Offline
      Paul Colby
      wrote on 27 Apr 2016, 22:09 last edited by Paul Colby
      #2

      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.

      K 1 Reply Last reply 28 Apr 2016, 10:09
      3
      • P Paul Colby
        27 Apr 2016, 22:09

        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.

        K Offline
        K Offline
        kshegunov
        Moderators
        wrote on 28 Apr 2016, 10:09 last edited by
        #3

        @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 ...

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        0

        1/3

        27 Apr 2016, 18:42

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved