So I created a script that live in /usr/local/bin called Linux-Permissions. In the script, there are some sudo cp commands. I need a user to be able to run the command as sudo, which I was able to do by adding this into the sudoers file: username ALL=(root) /usr/local/bin/Linux-Permissions. However, after he puts in his password to run that command, it asks for his password again to run the sudo cp inside the script. Since he doesn't have permission to run cp as sudo, this fails. The sudo commands inside the script are within a selection menu if that matters at all.

  • 3
    if you run the script with sudo everything inside also runs as "sudo".
    – user986805
    Jun 4, 2021 at 16:58
  • I removed sudo from everything inside and it works great! Not sure how to set your comment as the best answer.
    – TL_Arwen
    Jun 7, 2021 at 17:49

1 Answer 1


So, you have successfully identified the problem; adding an entry like that to sudoers only gives the ability to run /usr/local/bin/Linux-Permissions with sudo, so all of those other sudo commands will fail since, even though the script is being run with root privileges, sudo still sees that it's being executed by a normal user.

There are probably several different ways to approach this problem, but I would modify the script so that it only uses the sudo command if it is running as a non-root user. Here's a very simple example of a script like that:

#!/usr/bin/env bash
if [ "$USER" != "root" ]; then
  SUDO_CMD="sudo "


In that example, the ls command will be run with sudo if the script is being run as a normal user, but it will not use sudo if the $USER environment variable is set to root, which will be the case if you run the script with sudo.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .