First time here? Check out the FAQ!
1

Allow Wing IDE to debug non-root code using sudo python as a script

Could you please let me know a template script and configuration steps that allow me to run the python as sudo, I am not sure how to configure the python executable. The remote host already allow sudo without entering password.

I know this is possible but I haven't found where is documented, I am looking at the third option mentioned here link text

Many thanks in advance,

mhanuel's avatar
21
mhanuel
asked 2020-10-13 12:03:09 -0500
Wingware Support's avatar
4.1k
Wingware Support
updated 2020-10-14 08:00:14 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

2 Answers

1

We faced a similar challenge--except that we needed to use Wing in remote mode. We need some scripts to execute with sudo on the remote host.

We made a copy of the python3 executable file called "python3_privileged". Then we used setcap to set the capabilities we needed on python3_priviledged.

sudo setcap CAP_SYS_ADMIN,CAP_dac_override=eip \~/python3_privileged

adding the capabilities that you need. Then set Wing's project to use python3_privileged instead of python3. It's a bit of a pain to set up, and it requires some maintenance as you update Python.

TomBerk's avatar
36
TomBerk
answered 2020-10-14 15:30:01 -0500, updated 2020-10-14 16:51:55 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments
0

It may work to create a shell script with the following contents:

sudo python3 "$@"

Then make that executable on disk with 'chmod +x <filename>' and set it as the Python Executable in Wing's Project Properties (accessed from the Project menu).

This will not send in the environment set in Project Properties or inherited by Wing, and that may not be wanted anyway. If it is, you can use this instead:

sudo -E python3 "$@"

Also, of course, you may want just 'python' and not 'python3' or perhaps the full path of the Python you wish to run.

Wingware Support's avatar
4.1k
Wingware Support
answered 2020-10-14 09:38:35 -0500, updated 2020-10-14 09:39:17 -0500
edit flag offensive 0 remove flag delete link

Comments

Hi thanks for your answer, I was trying this solution but it seems now Wing IDE wants to use /root as the script and source code base path instead of my normal user. After trying to copy those files, Wing IDE seems to not be able to connect back to my Host machine. Do you have any idea what might be wrong?

mhanuel's avatar mhanuel (2020-10-15 11:38:36 -0500) edit

Are you able to read the files? It should be possible to work with them under /root (root's home directory) or to navigate to other directories such as the full path of the non root user's home directory. Note that you'll want to be careful of file permissions and ownership -- at least in my experience, it's always an issue when using different user accounts.

Wingware Support's avatar Wingware Support (2020-10-15 13:21:37 -0500) edit

If you're using a remote host configuration, you probably want to add the user name to the Host Name field, for example myuser@192.168.1.30. It sounds a bit like it was using the username 'root' but I'm not sure. Also, setting Base Directory under the Options tab may help.

Wingware Support's avatar Wingware Support (2020-10-16 10:35:52 -0500) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer