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?
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.