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

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

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.

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.

Related

How to change directory permissions like made with 'sudo mkdir' in linux

I created the directory with "mkdir" command, after that I need to change permissions as if I made it with "sudo mkdir".
I've searched for the chmod command, but it doesn't seem to be what I'm looking for.
Is it possible to do this with a single command in terminal?
you can use the chown command to change the owner and group of the directory, and the chmod command to set the permissions.
sudo chown root:root /path/to/directory && sudo chmod 755 /path/to/directory

Lost permission after chmod command

I accidentally executed the following command:
chmod -rwxr-xr-x folder_name
And after the command, I was not able to access the folder folder_name. I'm wondering if there is any way that I could recover the full permission to the folder.

How to give permissions for specific commands in linux

I am new to linux. I have a build.sh file which consists of a lot of mkdir commands and some rm commands. But as I have installed this new in my VB, each time I run the .sh file, it says "Permission Denied for creating directory" and fails.
So is there any way that I grant directory privileges to all users.
Can anyone help me with this
Add "sudo" in the beginning of the directory creation command i.e
sudo mkdir dir_name
The issue might be with the directory in which the mkdir command is being run.
Use the command ll or ls -l to check the directory permissions.
If your directory doesn't have write privilege for the current user, you can run
chmod -R u+w /path/to/directory
This might require you to use sudo if permission is denied.
If you want to enable it for all users, run
chmod -R ugo+w /path/to/directory
Alternatively, a quick fix would be to run the build.sh file as root
sudo /path/to/build.sh
However, this approach is not advised unless you always run it as root

How can I get "sudo chmod +x my_script.sh" to work? (operation not permitted) (Fedora 30)

I am attempting to make a file my_script.sh executable by using the sudo chmod +x my_script.sh command. I created the file my_script.sh with sudo gedit my_script.sh I did my writing in the file, then I used chattr +i /etc/resolv.conf to save the change.
I then attempted the sudo chmod +x my_script.sh command, but received the output chmod: changing permissions of '/rw/config/vpn/qubes-vpn-handler.sh': Operation not permitted. I've looked all over the web and on these forums and have found a number of posts offering solutions about changing ownership, etc. However, these all meet with the same result. I'm including some examples below, in case they're helpful:
[user#---]$ sudo chmod +x my_script.sh
chmod: changing permissions of 'my_script.sh': Operation not permitted
[user#---]$ sudo chmod +x my_script.sh
chmod: changing permissions of 'my_script.sh': Operation not permitted
[user#---]$ sudo rm my_script.sh
rm: cannot remove 'my_script.sh': Operation not permitted
[user#---]$ sudo chmod 0754 my_script.sh
chmod: changing permissions of 'my_script.sh': Operation not permitted
[user#---]$ sudo chown user my_script.sh
chown: changing ownership of 'my_script.sh': Operation not permitted
[user#---]$ sudo chmod u+x my_script.sh
chmod: changing permissions of 'my_script.sh': Operation not permitted
[user#---]$ sudo rm my_script.sh
rm: cannot remove 'my_script.sh': Operation not permitted
[user#---]$ sudo chmod -R a+x /[directory containing my_script.sh]
chmod: changing permissions of 'my_script.sh': Operation not permitted
If anyone can render assistance I would be most grateful.
It is because of the chattr +i have a look at the man page : https://linux.die.net/man/1/chattr.
It prevents any user including the root from modifying or deleting a file. You can do chattr -i to change that.

User cannot create file linux

may I know a command for root to change the mode to make the user able to create files.
I tried multiple times but I can seem to solve it.
[root#master ~]# useradd -d /opt/hadoop hadoop
useradd: cannot create directory /opt/hadoop
What are the permissions on /opt/hadoop? If you created the directory manually as root then it's probably owned by root and the user has no access to it - you'd need to chown -R it to the correct ownership.
chmod 755 /opt
chown root /opt
chmod 755 /opt/hadoop
chown -R user:user /opt/hadoop

Resources