-1

I’m running a bash srcipt using “sudo script.sh” beacause some of the commands inside script requires privileged access. How can I remove sudo while running the script but give access to commands inside the script?

1
  • 1
    Sigh... bash drop sudo in script. Among the questions and answers there are two different strategies discussed. Commented Jan 10, 2019 at 6:20

1 Answer 1

1

Instead of running the script with sudo, use sudo within the script for those specific commands.

The first command will prompt the user for their password. But sudo keeps an authentication cache, so it won't ask again for several minutes on the same terminal. As long as the script doesn't go too long between commands that need privilege, it shouldn't ask multiple times.

Sign up to request clarification or add additional context in comments.

18 Comments

Thanks....Can I remove a “sudo required command” from a for loop and call it from another script
Not sure what you mean by that, but why would it make a difference which script it's in?
I want to create script only with specific commands that require sudo
What does that have to do with a for loop? Maybe you should ask a new question that shows the details of what you're asking about.
You can put sudo script2.sh inside script.sh. Everything in script2.sh will be run as root.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.