Sudo chmod gets permissions denied

When I run ls -l, the file I want to change permissions of is:

-rw-r--r-- 1 82176 1491 193716029663 Feb 16 2019 cfdna_hc_bam.bam

First try: chmod 775 cfdna_hc_bam.bam. Result: chmod: changing permissions of 'cfdna_hc_bam.bam': Permission denied

Second try: sudo chmod 775 cfdna_hc_bam.bam. It asks for my password, I provide it and the Results: chmod: cannot access 'cfdna_hc_bam.bam': Permission denied.

When I enter cd .., ls -l, to see the permissions on the directory in which my file is, this is the result: drwxrwsr-x 1 93501 1491 8192 Sep 28 14:24 bam_files.

The only question I found similar is (Sudo chmod +x leads to "cannot access [file] permission denied"), and it had to do with a mounted image problem, which isn't my case here.

EDIT:

  • I created a file in this directory, and changed its permissions, and it worked:

    touch a
    chmod 755 a

    This works.

  • Then I did the same thing using 'sudo', and it didnt:

    touch a
    sudo chmod 755 a I get: `chmod: cannot access 'a': Permission denied`.
  • Also, when I run the command id I get:

    uid=1004(yonatan) gid=1005(yonatan) groups=1005(yonatan),27(sudo),132(docker)
  • Trying to run sudo chown yonatan:yonatan -R <dir> on the directory in which the file is (and also in above directories), results in: chown: cannot access 'bam_files': Permission denied.

10

1 Answer

  1. The directory was received from another user on the remote machine.
  2. You are not the owner of that machine so i suspect that the directory is "secured" from sudo command.
  3. Try to contact the user that you received the directory from and the root of the remote machine and ask them to run this commands:
    • chown -R yonatan:yonatan <filename> or chown -R 1004:1005 <filename> (wich is the same command).
    • if the root run the command he can run it directly on the file you have received.
    • if the user that sent you the directory running the commands he needs to run that on a copy in his own "home file" and then sent it to you with your uid and gid permissions.
  4. After you will be the owner of the directory try to run again the chmod command with the permissions you want.
    • for an example chmod 775 <filename>
  5. Remarks:
    • in your own specific case 93501 is the user that own the directory and 1491 is the group that own the directory.
    • another option for a solution is to add your own user to 1491 (by the root), but then if other group 1491 users have access to your directory they will still have permissions to the file.
    • i recommend to use this calculator as "permissions calculator"
    • if the following answer is failing to solve the problem please let me know on the comments so we can keep try to solve that out.
1

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