chmod: changing permissions of ‘my_script.sh’: Operation not permitted

Resolving the operation not permitted error:

sudo chmod u+x my_script.sh

You created the file via:

sudo vi my_script.sh
# editing

This means, the owner and group of the file is root. You are not allowed to change files of it by default. You need to change permission (chmod does it) or change the owner:

sudo chown you:yourgroup my_script.sh

This should do it. Save the trouble, without creating the file via sudo.


You've created file my_script.sh with the root user as the owner (because you used sudo), which is why you're not permitted to change the permissions as yourself.

Thus, use sudo chmod u+x my_script.sh, but note that that will make the file only executable for the root user.

To make the file executable by everyone, use sudo chmod a+x my_script.sh.

Tags:

Linux

Shell

Bash