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

when I'm trying to make shell script that error is shown ,what i must do ??

 [rehamadel@localhost bin]$ sudo vi my_script.sh

[sudo] password for rehamadel:[rehamadel@localhost bin]$ ls -l my_script.sh

-rw-r--r--. 1 root root 52 Jul 30 19:25 my_script.sh
[rehamadel@localhost bin]$ chmod u+x my_script.sh
chmod: changing permissions of ‘my_script.sh’: Operation not permitted
1

3 Answers

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.

0

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.

0

I faced this error because I uploaded the files via winscp and was trying to change permission on Linux window. I was able to change permissions via winscp.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like