在 Linux 中,如何在 Qt Creator 中添加一个使用 su 权限的构建步骤而不会在构建时尝试输入错误的密码? [英] In Linux how to add a build step in Qt Creator that uses su privileges without getting the wrong password attempts on builds?

查看:100
本文介绍了在 Linux 中,如何在 Qt Creator 中添加一个使用 su 权限的构建步骤而不会在构建时尝试输入错误的密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是将文件夹成功链接到/opt/目录 - 需要使用 sudo 运行.

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

我已经试过了:

 system(sudo ln -s $$OUT_PWD/xampp /opt/lampp):message("You should manually link LAMPP")

但是从 qt-creator 构建它不会提示输入 sudo 密码,因此我无法让它链接文件夹.我在编译器输出中收到错误的密码尝试..."错误.然后我用构建步骤尝试了这些:

But building from qt-creator it does not prompt for sudo password, therefore I couldn't get it to link the folder. I got the "wrong password attempts..." error in the Compiler Output. Then I tried these with build steps:

make
sudo make install

看看它是否会在那里提示我,但它在 make install 步骤失败并出现相同的错误,详细如下:

to see if it would prompt me there, but it failed on make install step with the same error, which is this in detail:

00:31:20: Starting: "/usr/bin/sudo" make install
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: no tty present and no askpass program specified
sudo: no tty present and no askpass program specified
Sorry, try again.
sudo: 3 incorrect password attempts
00:31:20: The process "/usr/bin/sudo" exited with code 1.

当我使用 qmake && 时,qmake 脚本中的 system() 函数工作正常制作&&make install 从终端,​​因为它在 sudo ln... 命令之前提示我;但为了快速测试的目的,我觉得在 Qt Creator 中使用 CTRL-B 构建也应该使用 sudo 命令......

The system() function in the qmake script works fine when I use qmake && make && make install from terminal since it prompts me before sudo ln... command; but for fast testing purposes I feel that building with CTRL-B inside Qt Creator should also work with sudo commands...

有没有办法从 Qt Creator 中得到提示,或者有办法解决这个问题?就像在 Qt Creator 中存储 sudo 通行证一样(尽管它有风险)......或者也许让它在终端上运行构建步骤,它会提示我?qmake 中的 prompt() 函数是否可以收集 sudo 密码?

Is there a way to be prompted from Qt Creator, or a way around this? Like storing the sudo pass within the Qt Creator (although it is risky)... Or maybe making it run build steps on a terminal where it would prompt me? Would prompt() function in qmake work with gathering sudo passwords?

欢迎任何建议...

推荐答案

经过大量研究:

ssh-askpass Sudo Password | sudo -S bash ./script

就像一个魅力,它要求在单独的窗口/提示框中输入密码.我在自定义构建步骤下添加了它.重要的是让 sudo 知道它需要通过 -S 选项输入密码.

Worked like a charm, it asks for the password in a separate window/prompt box. I added it under custom build steps. The important thing is to let sudo know that it will expect a password input via -S option.

echo "password" | sudo -S bash ./script

也适用于 bash 脚本,但是您可能认为将 sudo 密码存储在脚本中是不安全的.据说读取权限应该可以解决这个问题.

Also works with bash scripts, however as you might think it is insecure storing the sudo password inside the script. It is said that read permissions should fix that issue.

这篇关于在 Linux 中,如何在 Qt Creator 中添加一个使用 su 权限的构建步骤而不会在构建时尝试输入错误的密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆