Running application with user privillegions.
-
How running QProcess with user privilege?To make the application run with the user's password
-
Hi and welcome to devnet,
What you are asking is not clear.
A process started by a user already has its privileges.Can you describe what exactly should happen ?
-
Hi and welcome to devnet,
What you are asking is not clear.
A process started by a user already has its privileges.Can you describe what exactly should happen ?
@SGaist For example, i am want running with root, this is needed asked password.How implementation this is function?
-
Again, you have to be more precise.
Starting arbitrary binaries or doing specific actions have two different design paths.
Also, the OS is important as well. Which one are you targeting ? -
OS Debian GNU/Linux 13.4 trixie.
-
OS Debian GNU/Linux 13.4 trixie.
@nicholas_ru
There are 3 ways I know of under Linux:-
Invoke
suorsudoorrunuserorsetprivor others to run your program. Depending on your flavor you may be able to pass a password on the command line, standard input, environment variable or similar. -
Use
polkitandpkexecto configure the system to run certain programs with certain privileges. It does not require a login or password once set up. -
Make your executable file setuid to root or another user so it always runs with that user's privileges. It does not require a login or password.
QProcessis nothing but a wrapper around Linuxexec-type system calls. Nothing special about it. It could be used to run any of the above. -
-
please, describe code for this action, i am beginner.
-
please, describe code for this action, i am beginner.
@nicholas_ru
You need to investigate these alternatives to decide which suits your use case the best. You can use man pages or Google. They don't really require "programming" at your side. You should start with: what is it you are trying to do which requires running as another user and why? Why do you want to run what as root from where? Will you only be running this yourself, within your own organization or for distribution to others in the outside world? And btw is this to be a command line or UI Qt application? -
I used to before on js many years ago, maybe that command help you
// echo your-password | sudo -S your-command QString command = QString("echo %1 | sudo -S %2").arg(1234).arg("ifconfig") rocess->start(command) -
Debian running, for example, /usr/sbin/gparted, automatically with root requesting(without entering command sudo).How implementation this is, i am don't know.
-
Debian running, for example, /usr/sbin/gparted, automatically with root requesting(without entering command sudo).How implementation this is, i am don't know.
@nicholas_ru said in Running application with user privillegions.:
Debian running, for example, gparted, automatically with root requesting(without entering command sudo).How implementation this is, i am don't know.
I don't understand what you mean. Are you saying that the
gpartedcommand runs as root but doesn't ask for a password, whereas other applications do?For example, you may have entered a password for the
sudocommand in the same terminal before, or you may have granted permissions for thegpartedcommand. These are Linux-related tasks.If you need run command on qproccess with sudo and password: https://superuser.com/questions/67765/sudo-with-password-in-one-command-line
-
Debian running, for example, /usr/sbin/gparted, automatically with root requesting(without entering command sudo).How implementation this is, i am don't know.
@nicholas_ru said in Running application with user privillegions.:
How implementation this is, i am don't know.
This was answered by @JonB :
"Make your executable file setuid to root or another user so it always runs with that user's privileges. It does not require a login or password." -
@fnaf free Could you please provide an example or some sample code for this? I’m still a beginner and trying to understand how it works.
-
You could ask ai or search on google
sudo cp your_program.exe /usr/local/bin/your_program sudo chmod +x /usr/local/bin/your_programThese are Linux-related tasks.
-
You could ask ai or search on google
sudo cp your_program.exe /usr/local/bin/your_program sudo chmod +x /usr/local/bin/your_programThese are Linux-related tasks.
@Joe-von-Habsburg said in Running application with user privillegions.:
sudo chmod +x /usr/local/bin/your_program
It's already executable after the copy, and
chmod +xdoes nothing more than it already is. It does not make the executable run as root. You want/intended instead:chmod u+s path-to-executableso it will look like:
root@ubuntu-22:~/QtTests/C++/sudopassword/build/Desktop-Debug# chmod u+s fred root@ubuntu-22:~/QtTests/C++/sudopassword/build/Desktop-Debug# ls -l fred -rwsr-xr-x 1 root root 379112 Mar 30 08:48 fredNote the
-rws, thesthere.Note that you will need to repeat the
chmodevery time after you recompile/recopy your executable. If you redistribute your executable then wherever it gets installed the root user would need to choose to run thechmod u+sthere once, you cannot distribute (I don't think) with the executable owned by root and setuid. -
You have ubuntu. I have Debian. This is method change chmod, not exit for programmers.First post with running command very nice,but not full.
-
You have ubuntu. I have Debian. This is method change chmod, not exit for programmers.First post with running command very nice,but not full.
@nicholas_ru
Did you even try it?? Debian man page https://manpages.debian.org/bookworm/coreutils/chmod.1.en.htmlEach MODE is of the form
'[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+'.How else would you setuid under Debian? No point my suggesting things if they do work but you say they do not.
.First post with running command very nice,but not full.
If you mean @Joe-von-Habsburg 's
QString command = QString("echo %1 | sudo -S %2").arg(1234).arg("ifconfig")it won't work as written if passed toQProcess::start().... But I am getting a bit dispirited trying to help you so up to you. -
@nicholas_ru
Did you even try it?? Debian man page https://manpages.debian.org/bookworm/coreutils/chmod.1.en.htmlEach MODE is of the form
'[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+'.How else would you setuid under Debian? No point my suggesting things if they do work but you say they do not.
.First post with running command very nice,but not full.
If you mean @Joe-von-Habsburg 's
QString command = QString("echo %1 | sudo -S %2").arg(1234).arg("ifconfig")it won't work as written if passed toQProcess::start().... But I am getting a bit dispirited trying to help you so up to you.@JonB said in Running application with user privillegions.:
But I am getting a bit dispirited trying to help you so up to you.
:(
@nicholas_ru said in Running application with user privillegions.:
You have ubuntu. I have Debian. This is method change chmod, not exit for programmers.First post with running command very nice,but not full.
so ? linux is linux and there is a qt forum. we try to help you
-
@JonB said in Running application with user privillegions.:
But I am getting a bit dispirited trying to help you so up to you.
:(
@nicholas_ru said in Running application with user privillegions.:
You have ubuntu. I have Debian. This is method change chmod, not exit for programmers.First post with running command very nice,but not full.
so ? linux is linux and there is a qt forum. we try to help you
@Joe-von-Habsburg said in Running application with user privillegions.:
But I am getting a bit dispirited trying to help you so up to you.
:(
To be clear: it is the OP I am getting "dispirited" trying to help, not your posts! :)
He could use your code approach (perhaps, if that is what he wants), just that it needs changing to work. But since we (at least I) don't even know exactly what he wants I have not corrected it so far, waiting to see.....
-
@nicholas_ru
Did you even try it?? Debian man page https://manpages.debian.org/bookworm/coreutils/chmod.1.en.htmlEach MODE is of the form
'[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+'.How else would you setuid under Debian? No point my suggesting things if they do work but you say they do not.
.First post with running command very nice,but not full.
If you mean @Joe-von-Habsburg 's
QString command = QString("echo %1 | sudo -S %2").arg(1234).arg("ifconfig")it won't work as written if passed toQProcess::start().... But I am getting a bit dispirited trying to help you so up to you.@JonB i am think in Qt framework must be integrated this is function.