Ubuntu – How to change default permissions on automounted usb flash, formatted in NTFS?

automountntfspermissionsusb

I have an Ubuntu 14.04 installed on my computer with XFCE as Desktop environment. When i'm inserting usb flash formatted in NTFS system mounts it with default permissions on files are setted in 600, and I want to change this behaviour to mount with default permissions 660 instead. How can I do it?

Best Answer

Mount NTFS partition in a USB drive with custom permissions and owner

Assumption: the USB drive is seen as sdb1, modify to match the drive letter and partition number in your case. The general syntax is sdxn, where x is the drive letter and n is the partition number as seen by for example sudo lsblk -f

You can use the following command line method in order to get other permissions and ownership than the default.

Create mountpoint (only if you want a new mountpoint)

sudo mkdir -p /mnt/sd1

Unmount (only if already mounted)

sudo umount /dev/sdxn   # general syntax
sudo umount /dev/sdb1   # modify to match your case

Check your userID's uid number (it is usually 1000, sometimes 1001 or 1002 ...)

grep ^"$USER" /etc/group

and use that number if you want to grab ownership (default is root).

Example of mount command line that should give you something that is close to what you want,

sudo mount -o rw,users,uid=1000,dmask=007,fmask=117 /dev/sdxn /mnt/sd1  # general syntax
sudo mount -o rw,users,uid=1000,dmask=007,fmask=117 /dev/sdb1 /mnt/sd1  # modify to match your case

Example with full permissions for everybody (convenient, but not safe, when there are several users),

sudo mount -o rw,users,umask=000 /dev/sdxn /mnt/sd1  # general
sudo mount -o rw,users,umask=000 /dev/sdb1 /mnt/sd1  # modify to match your case

Check permissions and owner of the directories and files

ls -ld /mnt/sd1
ls -ld /mnt/sd1/*

Test

sudo bash -c "echo 'Hello World' > /mnt/sd1/hello.txt"  # test writing with sudo
cat /mnt/sd1/hello.txt                   # test reading (as user)
ls -l /mnt/sd1                           # check permissions of the content
rm /mnt/sd1/hello.txt                    # test removing (as user)
echo 'I am a user' > /mnt/sd1/user.txt   # test writing (as user)

If this does not work

If this does not work, you may find a solution or at least an explanation at the following link,

Can't format my usb drive. I have already tried with mkdosfs and gparted: Analysis of the problem

Related Question