How to run sudo script from "external tools" in IntelliJ / WebStorm / PhpStorm?

I want my root-requiring bash script to run from IntelliJ / WebStorm , asking me for the root password when I run it. Of course, my root password is hardcoded in the script.

IntelliJ / WebStorm has a $ Prompt $ macro for such reasons, which asks you and uses your input as a value.

So I tried using $ Prompt $ along with echo YOURPASSWORD | sudo -S yourcommand echo YOURPASSWORD | sudo -S yourcommand as described in use-sudo-with-password-as-parameter .

Then I pass passwd and script to run until sudorun.sh script echo -e $1 | sudo -S $2 $3 $4 echo -e $1 | sudo -S $2 $3 $4 (since echo cannot be a "program"), which although it works in the CLI, cannot read echo-stdin in the IntelliJ console.

Ideally, I would like the solution to be configured exclusively from IntelliJ and not require specific OS configuration changes outside of IntelliJ.

There may be other ways to deal with this, so let's improvise!

+4
source share
3 answers

I also faced the same problem, but I work with confidential data on my development machine and password removal for sudoers is simply not an option.

I was able to solve this problem by starting the WebStorm application from the command line using the sudo command as follows:

sudo /Applications/WebStorm.app/Contents/MacOS/webide

After running WebStorm / PhpStorm, you can run the script with root access without providing root credentials.

+5
source

Use the NOPASSWD function sudo . Add a rule like this to sudoers (via visudo or the like):

 someuser ALL = NOPASSWD: /usr/bin/interesting_program %somegroup ALL = NOPASSWD: /usr/bin/interesting_program 
+4
source

I find myself automating many of my work processes and working on the same issue. I do not want to punch a hole in my sudoer permissions, and I also do not want to run my IDE with root privileges. A good solution I found is gksudo , on Ubuntu and many other Linux variants, you will find it installed by default. What gksudo does is let the user (himself) enter a password with a graphic overlay, like Ubuntu / KDE / etc. when you need to be root to perform an operation such as updating.

You will then be asked to provide a password for escalating privileges, and then execute the given command / program with root privileges.

In the "Edit Tool" window, simply:

  • Install the program on /usr/bin/gksudo
    • gksudo may be in a different path, try: whereis gksudo find its path
  • Set options for all the commands you want to execute in quotation marks
    • Ex. "mongod --fork --config /etc/mongodb.conf; service elasticsearch start"
    • Make sure you have quotation marks!
  • Set working directory (if necessary)
+3
source

Source: https://habr.com/ru/post/1442193/


All Articles