I'm trying to run a program written in C/C++ by using CLion 2022.3.2 as superuser. Anyone here knows how to run it as superuser? I'm using CMake.
I solved this by remote debugging on local machine. I run gdbserver with root privileges and connected to it from CLion.
To start gdbserver sudo gdbserver :port myapp
, configure remote GDB debug with port
If you are asking to run the debugger as sudo/administrator, I had the same issue. On Linux you can open CLion as sudo and gdb will not have root permission issues running an executable:
sudo ./clion.sh
I would guess that you could right click in Windows and "Run as administrator" to get the same result.
There is a feature request into JetBrains to run the debugger as root that could use more up voting.
sudo -i
then clion.sh
-- haven't had an issue with it crashing. Ubuntu 16.04 / 18.04 –
Mcneill This was already implemented on CLion, starting 2020.3:
A workaround is:
From https://www.jetbrains.com/help/clion/attaching-to-local-process.html#prereq-ubuntu
If you are using CLion on Ubuntu (or probably, on some other Linux distribution), upon the first attempt to attach to the local process you can get the ptrace: Operation not permitted. error message. To disable it and enable attach to the local process feature, do the following:
To disable this restriction temporarily, enter the command:
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
To disable this restriction permanently, open the file /etc/sysctl.d/10-ptrace.conf
for editing and change the line kernel.yama.ptrace_scope = 1
to kernel.yama.ptrace_scope = 0
. To apply the changes, enter:
sudo service procps restart
or restart your system, at your choice.
TL;DR
One liner copy pasta. Paste this command into a terminal window, run your process, come back to the terminal window and type your password.
pkttyagent --process $(ps -o ppid= $(pgrep -f clion) | sort -n | tail -n1)
Solution
Find CLion's top-most (parent of all open projects) process ID (PID) whose PPID is 1.
$ ps -f $(pgrep -f clion)
UID PID PPID C STIME TTY STAT TIME CMD
thisisme 348892 1 7 Jun05 ? Sl 1041:34 /opt/clion...
Launch the pkttyagent
with this process as its argument.
$ pkttyagent --process 348892
Launch your process with CLion's run configuration set to run the process as root.
The pkexec
process will connect to the tty agent running in your console and prompt you for the password. Enter your password in the console window and your process will continue to run as root in CLion.
0 thisisme@iamhere:~/indir$ pkttyagent --process 348892
==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run `/opt/clion-2022.2.4/jbr/bin/java' as the super user
Authenticating as: thisisme,,, (thisisme)
Password:
==== AUTHENTICATION COMPLETE ===
Discovering This Solution
Found these interesting bits of info while using Ubuntu 22.04 and Mint 21 vanessa.
Assuming you are not the root user, notice that when you run something like systemctl restart polkit
, you are prompted to enter a password. Before entering your password press ctrl-c, then type systemctl status polkit
and you'll see that a pkttyagent process is launched.
Similarly, in the status output when running pkexec ls
in another terminal, you'll see that polkit.service status prints the executable and arguments like pkexec ls
. This was the clue that we should launch the agent in another process instead of invoking pkexec directly. It seems like CLion is launching pkexec
without first starting an agent, so we need to wire up the agent for CLion ourselves.
Reading the man page on the pkttyagent, it takes a PID which listens for elevation requests. All you gotta do is start an agent, and elevation requests from that PID show up in your console.
Note on Build Systems
It does not matter if CMake or Makefiles are used to build the project; the set up steps are the same.
You can create a bash script to help you. For example, run.sh
:
#!/usr/bin/env bash
echo $LOGIN_PASSWD | sudo -S yourExecutable --with=some-arguments
Don't forget to chmod a+x run.sh
, and export the password of current account as an environment variable in Run/Debug Configurations.
© 2022 - 2024 — McMap. All rights reserved.