sudo-prompt icon indicating copy to clipboard operation
sudo-prompt copied to clipboard

How to run multiple commands without requiring password every time

Open tutiplain opened this issue 3 years ago • 6 comments

Hi! I just began using sudo-prompt and while it works for me, I find it has the drawback of asking me for the password for every single command I run with it. Is there a way to get it to remember the password?

tutiplain avatar Jul 26 '21 22:07 tutiplain

I have same problem,Looking forward to a reply

nobody-sun avatar Jul 27 '21 02:07 nobody-sun

@nobody-sun It looks like we won't be getting an answer here. I found a workaround that might work depending on your needs. Instead of running multiple commands, you can concatenate your commands into a string separating them with && and do a single call to sudo-prompt. This will allow you to call multiple commands and entering a single password. This helps if all the stuff you need to do can be done with OS commands. If you need run separate commands at different points in your app, then this approach won't help. I'm still looking for alternatives. If I find any I'll post here again.

I also tried another library, electron-sudo. That one did not work at all for me.

tutiplain avatar Jul 27 '21 22:07 tutiplain

I think that we should use sudo to create launchd job, it can help once sudo dialog for multiple commands.

PeterKieu avatar Jul 30 '21 11:07 PeterKieu

I have same problem,Looking forward to a reply

night-peiqi avatar Aug 31 '21 08:08 night-peiqi

@Awn-Alice Your best bet at this point is to concatenate your commands using && and running them all at once. For me this required refactoring some operations done in code, to doing them in bash commands. It it not a pretty solution, but it worked for what I was doing. Creating a launchd job sounds like an option, but it can be tricky to use, and its behavior can change on future Mac OS releases.

tutiplain avatar Sep 01 '21 11:09 tutiplain

@tutiplain Thank you for your reply, but this scheme may not be suitable for my situation. I may need to modify hosts file frequently. However, every time I change it, I have to enter the password

night-peiqi avatar Sep 04 '21 10:09 night-peiqi