10

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?

5
  • Can you please post the output of ls -l /home/david and ls -l /home/david/documents? That will show us that you have correct permission to the folders. Also, you aren't perhaps creating these scripts with sudo, i.e. sudo nano monitor-off.sh, or sudo wget http://somewebsite.com/monitor-off.sh, right?
    – reverendj1
    Aug 8, 2012 at 20:14
  • Oops, I meant ls -ld /home/david and ls -ld /home/david/Documents.
    – reverendj1
    Aug 8, 2012 at 20:25
  • david@my-pc:~$ ls -ld /home/david drwxr-xr-x 28 david david 4096 Aug 9 08:57 /home/david david@my-pc:~$ ls -ld /home/david/Documents drwxr-xr-x 4 david david 4096 Aug 8 16:01 /home/david/Documents
    – wecsam
    Aug 9, 2012 at 13:52
  • Gah, I can't make the line breaks appear.
    – wecsam
    Aug 9, 2012 at 13:53
  • Oh, just add them to the answer. I can see they are correct though.
    – reverendj1
    Aug 9, 2012 at 13:57

1 Answer 1

12

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
2
  • Hm, that's weird. I created those files in gedit running under my user account. Do you know how that could have happened? Both /home/david and /home/david/Documents are owned by me.
    – wecsam
    Aug 9, 2012 at 13:55
  • @EliahKagan tried the command and root still has ownership for targeted folder, would this be affected if the folder(volume) is in a docker container? (Mac OSX)
    – Kubie
    Jun 24, 2019 at 19:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.