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
You got this error because your user is not the owner of /root folder. So you can't change the permission of your folder other than the root user. You need to switch to your root account and run the commands as shown below.
chmod +x Add Execute Privilege For User The chmod +x can be used to add execution privilege the current owner user of the specified file. In the following example we will add execution privilege for the user ismail to the file named backup.sh .
root user run the chmod -R 777 / command and all file permissions for the entire system have read/write/execute for every user.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With