Ubuntu – Can’t Change Permissions of Files in Home Folder without Sudo

filespermissionssudo

For some reason, I can't chmod +x files that are right in my home folder without prepending sudo to the command.
One recent example: I have a file named monitor-off.sh in ~/Documents. I tried to use this command at the terminal and received this message:

david@my-pc:~/Documents$ chmod +x ./monitor-off.sh
chmod: changing permissions of `./monitor-off.sh': Operation not permitted

However, when I prepended sudo to the beginning, it worked:

david@my-pc:~/Documents$ sudo chmod +x ./monitor-off.sh
david@my-pc:~/Documents$ ls -lh
total 28K
... (files) ...
-rwxr-xr-x 1 root  root    44 Aug  8 15:32 monitor-off.sh
... (files) ...

I know that I shouldn't be overusing sudo like this, so what can I do to fix things so that I can use chmod without sudo?

Best Answer

It seems to be a permission issue. From the output i can see, that the file is owned by root. Only from the root account (but including with sudo) you can make changes to the file's permissions. You need the change the ownership of the file. Run this command in the Terminal to take ownership of all the files in your home directory:

sudo chown -R $USER:$USER $HOME
Related Question