I am using Eclipse CDT to write an application. The application uses a third part API, which requires to run as sudo, in order to open raw sockets, etc.
In command line, I can run the program something like
su
./program
But in Eclipse CDT environment, it won't work if I press Ctrl + F11 (Run->Run Last Launched), I guess the reason is that my Linux GUI login is not su.
Is there anyway that I can run as su (with su password) in Eclipse CDT?
Thanks.
Some of the options you have:
Run Eclipse as root. (Not a very good idea, imho, but the simplest one)
Temporarily enable your user to use that library. (Could be messy)
Create a new run configuration and make a script to run your executable.(You've to enter the password everytime).
(@Others, feel free to add more.)
You can create a run configuration in which you use sudo to run your application. Since sudo
doesn't have access to a terminal if you launch it this way, it requires setting the SUDO_ASKPASS
environment variable in your launch configuration. The steps are as follows:
Creating a new Run configuration (for the sake of completeness):
Modifying the Run configuration
/usr/bin/sudo
../bin/my-executable
. Note: sudo
's working directory is the eclipse project, so the path should be relative to that../bin/my-executable arg1 arg2
Adding a way for sudo
to ask for your password.
sudo
does not have a terminal (tty) at its disposal when run from the (eclipse) gui, we need to provide it with a program that can obtain the password for it, i.e. an askpass program. For more info, see this stackoverflow answer.ssh-askpass-gnome
provides an askpass program, as I found out by running dpkg --get-selections | grep askpass
. Since that still didn't give me the executable name, I brute-forced the search by running
sudo find -name *askpass*
. Anyway, if no such utility is installed, search for it using your favourite package manager.SUDO_ASKPASS
as name and the full path to the askpass program as value, e.g. /usr/bin/ssh-askpass
.sudo
password will appear.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With