USB Drive - Not able to change file permissions

7,620

You can set up /etc/fstab as a way of configuring drives. To pick out or identify a specific partition to mount, we can use the partition's UUID, which can be found with blkid

sudo blkid

In order to mount the drive, you need an empty directory. The user you wish to have access to the files needs access to this directory, including +x:

sudo mkdir /mnt/MyDrive
sudo chown me:me /mnt/MyDrive
sudo chmod 770 /mnt/MyDrive

Where me:me is the user:group string. On most systems, the first non-root user created at install will have the uid of 1000, and gid of 1000, but you can check /etc/passwd and /etc/group to confirm these numbers match up on your system for the next step.


Now that you know which partition to mount, and you have a place to mount it, work on a new entry in /etc/fstab

UUID=id-without-quotes  /mnt/MyDrive   ext4   defaults,noauto,uid=1000,gid=1000

Additional details about /etc/fstab can be found in the Ubuntu Wiki. The details found in the wiki will help you fine-tune settings, such as auto-mounting when inserted, or setting default umask. Another interesting option is the users option, which allows non-root users to mount the filesystem.

sudo mount /mnt/MyDrive
sudo umount /mnt/MyDrive

If you need to share these files with other users, create a new group, add all of the users to the group, and then adjust the gid to match the new group's identifier. You can see other examples of this, such as httpd or nginx using the www-data user/group.

Share:
7,620

Related videos on Youtube

David
Author by

David

Computer Engineering Tech Major Fluent in .NET, bash, and TypeScript AU User since mid-2015 Using ubuntu since 9.04

Updated on September 18, 2022

Comments

  • David
    David over 1 year

    Now, please note that this is a sub-question of my old Changing Ownership: “Operation not permitted” - even as root! question. If you do not want to visit that link or cannot, to sum up, while attempting to use:

    sudo chown (...)
    

    To change the ownership of a file inside of a USB drive, it was unsuccessful, as the file had the immutable flag set in its extended attributes. This was the solution that worked, removing the flag via:

    sudo chattr -i (Path_To_File)
    

    As this was fixed, I basically put this in the back of my mind where I would remember it in case of repetition of the error. Recently, I was formatting a USB custom, and ran into the same error, except this time, nothing that was suggested to fix said error the previous time, has worked. Here's your command output that I know you all love:

    sudo chown david:david ~/USB5/Format/type.cr
    

    Please note that I have checked this command, and neither the (~) general path, nor the specific path work. The following is my output:

    Operation Not Permitted
    

    Of course, I have tried the fix from before, and the file does not have the flag. What can I do to fix this?

    Suggested answer below:

    sudo mkdir /media/flash
    sudo mount /dev/sdb1 /media/flash -o dmask=000,fmask=111
    

    This just hangs on the second command, I left the computer for over 2 hours, just hanging.

    EDIT: Changing to EXT4 Did nothing, same error.

    • syss
      syss about 8 years
      which filesystem are you using on your USB drive?
    • syss
      syss about 8 years
      Then you might want to take a look at this questions: askubuntu.com/questions/118199/… askubuntu.com/questions/11840/… Basically you need to remount your partition with the correct rights.
    • acejavelin
      acejavelin almost 8 years
      Fat and NTFS are not native Linux file system types, therefore do not support Linux file attributes. Use a native Linux file system like Ext2/3/4 or F2FS.