In Linux how to add a build step in Qt Creator that uses su privileges without getting the wrong password attempts on builds?

后端 未结 4 1743
故里飘歌
故里飘歌 2021-01-02 20:36

My goal is to successfully link a folder to /opt/ directory- which needs to be run with sudo.

I have tried this:

 system(sudo ln -s $$OUT_PWD/xampp /         


        
4条回答
  •  遥遥无期
    2021-01-02 20:54

    @Logan You can cause sudo to use the ssh-askpass (GUI password request dialog) directly with its -A option, this can use the SUDO_ASKPASS environmental variable to override a /usr/bin/ssh-askpass value that may be configured in /etc/sudo.conf[1] (like the suggestions of gksudo or kdesudo from @herophuong ). This gets around the security risk of the second solution in your answer that leaves the "password" visible to anything that can observe the commandline arguments. The equivalent to your first solution becomes:

    sudo -A -s ./script
    

    Don't forget that sudo may provide credential caching so that, if it has been used very recently (default 5 minutes?), a repeated invocation uses that cached password value instead of making another password request. If, for sanity/security reasons, this is not desired for a script (or elsewhere) use sudo -K with no other arguments to immediately clear any cached credentials (no password is needed for that usage) so that any subsequent sudo usage will require authentication.

    1 - Remember to use visudo as root if you wish to edit /etc/sudo.conf to add:

    # Path to askpass helper program
    Path askpass /usr/bin/ssh-askpass
    

提交回复
热议问题