2

This question already has an answer here:

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?

marked as duplicate by muru, karel, Community Sep 15 '17 at 7:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Unless you're using the same USB drive again and again, in which case you should set up /etc/fstab mount using options inhttps://askubuntu.com/a/11843/158442, plus the option nofail. – muru Sep 15 '17 at 5:43
  • Sounds sad. So it seems not possible to implement such behaviour for any mounted flash. – razamanaza Sep 15 '17 at 6:11
  • 1
    It is possible, at least something very close to what you want, with command lines in a terminal window. I will write an answer to explain. – sudodus Sep 15 '17 at 6:43
  • @muru, The OP, razamanaza, seems to be happy with my answer. Would it be meaningful to edit this question, for example to remove 'default permissions' and 'automounting', and after that reopen this question? -- I think that otherwise people will not notice it (and not be helped, but instead learn that this is impossible due to the link to the 'original question'). -- Or should I move my answer to the 'original question' of the link or to another and better 'original question'? – sudodus Sep 15 '17 at 9:15
  • @sudodus why bother? It's not like your answer is going to be deleted, or this post will be hidden from search results. Besides, the generic solution to mount NTFS partitions with some mode is given in the other post to I linked to, so either way, it's a duplicate. – muru Sep 15 '17 at 9:48
2

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

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