26

I am trying to use my ext4 USB drive but Ubuntu 13 is currently mounting it with write permission only for root so with my normal user I can't write to it, without sudo.

The first place I checked was dconf-editor which has the following options

  • automount
  • automount-open
  • autorun-never
  • autorun-x-content-ignore
  • autorun-x-content-open-folder
  • autorun-x-content-start-app

and it seems to me there should be an option in there to control if I can write to the mounted USB drive, but no.

I also made sure my user is in the relevant groups: fuse and plugdev

I've searched most of the internet and can't find a solution to change the permissions given by the mount operation. There's literally nobody out there having this problem incredibly. A ton of people have issues because their drives mounts totally read-only, but not this way with only root write permission.

I can't see any way of controlling what happens. I looked at setting the mount options using gnome-disks but drew a blank.

It's not in fstab but it does appear in the mount list or /etc/mtab:

/dev/sdb1 /media/adam/WDPassport2T ext4 rw,nosuid,nodev,uhelper=udisks2 0 0

This is what appears in syslog if it helps:

kernel: [111522.196770] usb 2-1: USB disconnect, device number 6
kernel: [111525.384020] usb 2-1: new high-speed USB device number 7 using ehci-pci
kernel: [111525.565220] usb 2-1: New USB device found, idVendor=1058, idProduct=0820
kernel: [111525.565225] usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=5
kernel: [111525.565227] usb 2-1: Product: My Passport 0820
kernel: [111525.565229] usb 2-1: Manufacturer: Western Digital
kernel: [111525.565231] usb 2-1: SerialNumber:  575832314141334A34383631
kernel: [111525.565729] usb-storage 2-1:1.0: USB Mass Storage device detected
kernel: [111525.566203] scsi9 : usb-storage 2-1:1.0
mtp-probe: checking bus 2, device 7: "/sys/devices/pci0000:00/0000:00:1d.7/usb2/2-1"
mtp-probe: bus: 2, device: 7 was not an MTP device
kernel: [111526.564697] scsi 9:0:0:0: Direct-Access     WD       My Passport 0820 1007 PQ: 0 ANSI: 6
kernel: [111526.565063] scsi 9:0:0:1: Enclosure         WD       SES Device       1007 PQ: 0 ANSI: 6
kernel: [111526.568096] sd 9:0:0:0: Attached scsi generic sg2 type 0
kernel: [111526.568202] ses 9:0:0:1: Attached Enclosure device
kernel: [111526.568263] ses 9:0:0:1: Attached scsi generic sg3 type 13
kernel: [111531.263108] sd 9:0:0:0: [sdb] 3906963456 512-byte logical blocks: (2.00 TB/1.81 TiB)
kernel: [111531.265100] sd 9:0:0:0: [sdb] Write Protect is off
kernel: [111531.265105] sd 9:0:0:0: [sdb] Mode Sense: 47 00 10 08
kernel: [111531.266473] sd 9:0:0:0: [sdb] No Caching mode page found
kernel: [111531.266479] sd 9:0:0:0: [sdb] Assuming drive cache: write through
kernel: [111531.272224] sd 9:0:0:0: [sdb] No Caching mode page found
kernel: [111531.272230] sd 9:0:0:0: [sdb] Assuming drive cache: write through
kernel: [111531.284885]  sdb: sdb1
kernel: [111531.288219] sd 9:0:0:0: [sdb] No Caching mode page found
kernel: [111531.288223] sd 9:0:0:0: [sdb] Assuming drive cache: write through
kernel: [111531.288227] sd 9:0:0:0: [sdb] Attached SCSI disk
kernel: [111531.751588] EXT4-fs (sdb1): mounted filesystem with ordered data mode. Opts: (null)
udisksd[3131]: Mounted /dev/sdb1 at /media/adam/WDPassport2T on behalf of uid 1000
10
  • Try running sudo umount /dev/sdb1, and then mounting it as a normal user. The mtab entry has user=adam, which should mean user adam can use it...
    – Wilf
    Jan 15, 2014 at 17:55
  • @wilf actually it's the second mtab entry that has user=adam, not the USB drive. I don't know what that gvfsd-fuse stuff is. Probably irrelevant but I am puzzled why one entry has it, but not the usb drive.
    – Adam
    Jan 15, 2014 at 20:21
  • Whoops... Should pay more attention. The entries themselves are fine, so it should work... Do you mount and unmount the drive graphically, or via command line? - running gvfs-mount -d /dev/sdb1 should mount the drive, also should udisks --mount /dev/sda5. These should not require the root password, as they use the gvfsd entry to allow access.
    – Wilf
    Jan 15, 2014 at 21:12
  • so gvfs does have something to do with it. i am currently mounting and unmounting the drive graphically via nautilus, but i actually want it to be done automatically on attachment so that the backupdb process can use the drive. occurs to me that this is another problem even if i get the write permissions sorted.
    – Adam
    Jan 15, 2014 at 21:18
  • 1
    @Adam, what's the filesystem type of your USB device? and what does ls -ld /media/adam/WDPassport2T and ls -l /media/adam/WDPassport2T output?
    – rusty
    Jan 16, 2014 at 14:50

4 Answers 4

31

A possible reason could be that you formatted/created the storage disk with a tool with root privilege and so the file-system created was owned by the root.

Let's have a look at the o/p of your ls commands:

$ ls -ld /media/adam/WDPassport2T
drwxr-xr-x 4 root root 4096 Jan 15 16:57 /media/adam/WDPassport2T
$ ls -l /media/adam/WDPassport2T
total 20 
drwxr-xr-x 2 root root 4096 Jan 15 16:57 backuppc 
drwx------ 2 root root 16384 Jan 15 15:37 lost+found

The file-system is owned by the root, as indicated by ls -ld for your mount WDPassport2T and the permission string drwxr-xr-x shows the owner root has the RW permissions while, the members of group root along with the world/others will only have R-permission.

To solve you could change the permissions with chmod or just change the ownership recursively, and this is what I've shown below:

sudo chown <username>:<groupname> -R /path/to/target

which in your case would be:

sudo chown adam:adam -R /media/adam/WDPassport2T/

Now if you need, you may also set the permissions with chmod:

find /media/adam/WDPassport2T/ -type f -execdir chmod 666 -Rv {} +

(which gives owner, group and the world RW permissions for all the files in the target.)

find /media/adam/WDPassport2T/ -type d -execdir chmod 777 -Rv {} +

(which gives owner, group and the world RWX permissions for all the directories in the target.)

Reference:

Official Ubuntu Documentation: File Permissions

6
  • Fantastic. I didn't think of trying that because I just assumed the file permissions on /media/adam/WDPassport2T were set by the mount process, i.e. I didn't realise the actual USB drive (or its allocated mount point) would obtain and keep permissions. So there would be similar issues with permissions / ownership if I plugged the disk into another box?
    – Adam
    Jan 16, 2014 at 21:39
  • 1
    @Adam: "...would there be issues with permissions/ownership if I plugged the disk into another box?" well I'm not sure so I posted this Q: How portable are the works chmod and chown commands? ..if want to have RW permissions for the files/directories in other systems as well, you could allow RW for the world/othrs using chmod, please refer to the updated answer...
    – rusty
    Jan 17, 2014 at 5:40
  • If I formatted a USB drive ext4 using gksu gparted, would that automatically make me the owner of that USB drive, or would if still be formatted with root as owner?
    – Marc
    Jan 2, 2016 at 21:51
  • This doesn't work. I am still getting operation not permitted when I try and chown anything on that mount point.
    – Fr0ntSight
    Jul 1, 2019 at 5:58
  • 1
    But the question is why is the drive mounted as root in the first place. Is there a setting I can set so that in the future the drive is mounted by my user instead?
    – a06e
    Nov 13, 2019 at 10:34
3

Have you tried re-formating the drive with your own permissions?

First, check your user id:

sudo id -u red

It should give "1000"

Next, unmout the drive in filemanager.

Be careful, you will lose all your data with the next comand

sudo mkfs.ext4 /dev/sdx1 -E root_owner=1000:1000

Mount the drive and you should be able to write files and folders

1
  • This, actually, should be the primary answer, because it addresses the root problem of why the OS creates the /media/user-id/mount-point directory with the owner being root in the first place! May 29, 2020 at 10:28
1

Most partitioning & formatting tools (like Gparted) requires the root privileges.

File systems like ext4, ext3 stores file ownership information with the pen drive itself. (But the ntfs, fat32, fat16 does not have a security like that)

In this case you have to change the permission by using the following command in the terminal.

chown -hR nobody:nogroup /media/adam/WDPassport2T/

by setting the user as "nobody" & the group as "nogroup" it will fix the similar issues with permissions / ownership when plugged the disk into another box.

for more info see the manual page for chown command (use "man chown" )

1
  • It's nobody alright. But my user id isn't nobody, and it is preventing me to write.
    – K3---rnc
    Dec 12, 2016 at 23:11
0

The file-system is owned by the root, as indicated by ls -ld for your mount WDPassport2T and the permission string drwxr-xr-x shows the owner root has the RW permissions while, the members of group root along with the world/others will only have R-permission.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .