21

When I plug in my external Hard drive, insert a DVD, or try to see what I've got on my USB drive, peculiar behavior is the usual outcome.

The filesystems mount fine. When I log in as root through sudo su, I can see the contents of the /media/casper/externaldrive perfectly fine. My user however, casper, can't. Ubuntu replies to every action that involves the location Permission denied:

casper@casper-desktop:/media$ ll /media/casper/externaldrive
ls: cannot access '/media/casper/externaldrive': Permission denied

I decided to do some digging into the permission (problems) of the /media folder. As casper, I see the following:

casper@casper-desktop:/media$ ls -alF
total 16
drwxr-xr-x  4 root root 4096 apr 21 17:47 ./
drwxr-xr-x 25 root root 4096 jul 29 15:43 ../
drwxr-x---  3 root root 4096 aug  3 21:02 casper/
lrwxrwxrwx  1 root root   45 apr 21 17:47 .directory -> /etc/kubuntu-default-settings/directory-media
lrwxrwxrwx  1 root root   42 apr 21 17:47 .hidden -> /etc/kubuntu-default-settings/hidden-media
drwxr-xr-x  2 root root 4096 feb 29 23:56 home/

What struck me was that it said total 16, while there are only at most 6 listings. So I ran the command again, but as root. The result was the same, weird. (can anyone enlighten me on this?)

Anyway, what struck me even more was that the /media/casper directory is not mine and also can't be accessed by me. I got tempted to just chown -R the bazinkas out of it, but after I got a hold of myself I googled something like "Media user folder not mine help me".

It took a while but finally I stumbled upon this thread, where users explain the purpose of 750 root:root /media/user folders. It makes sure only root can mount, view and manage filesystems there, of which the individual permissions are changed to the actual user.

So if my information was correct, the /media/casper/externaldrive permissions should be favorable for me. I checked,

root@casper-desktop:/media/casper# ll
total 12
drwxr-x--- 3 root   root   4096 aug  3 21:02 ./
drwxr-xr-x 4 root   root   4096 apr 21 17:47 ../
drwxrwxrwx 1 casper casper 4096 aug  3 20:20 externaldrive/

And this seems to be the case.

So this is where I'm stuck. The filesystem has permissions for me all the way through the directory tree, yet I can't access a single file. This is the same for CD's and USB drives.

Who can help me access my precious?

Oh, and by the way. Aforementioned thread speaks of ACL on these /media/user folders, indicated by a + after the regular permissions, like drwxr-x---+ 3 root root. My system does not show this. Is ACL on these folders standard for Ubuntu or did the user have special things going on, and should I be worried that this is where my problem comes from?

Thanks for reading.

4
  • 1
    I use a dual boot setup (16.04 and Win7) and I see a + at the end of the permissions of folder /media/user. So I think there's where your problem comes from. I found these (1, 2) through googleing but I haven't used acl before to know if they are enough to solve your issue.
    – Karsus
    Aug 9, 2016 at 16:57
  • 2
    The ls total count 1kB blocks used by the files in the directory, non-recursively. See unix.stackexchange.com/a/4110/44281 .
    – amotzg
    Aug 9, 2016 at 21:04
  • @Karsus Thank you, I think you've found my problem. I'm going to try Zanna's answer below and will keep you updated. @ amotzg Aha, that clears things up. Thanks :) Aug 11, 2016 at 11:36
  • Just out of curiosity, what does "3" in drwxr-x--- 3* mean? Feb 25, 2019 at 16:33

3 Answers 3

24
+50

Since the permissions & ownership of /media/casper are

drwxr-x---  root root 

With no + for ACLs (Access Control Lists) it's clear that only root can open, enter, read or write to this directory. Humble users like us get the permissions at the end of the string --- :(

We unprivileged folk get permission to access this location with ACLs. I am not sure why you don't have these already, but you can set them up, which may be simple or require a little tinkering:

  • the acl package is required (check apt-cache policy acl)
  • the filesystem must be mounted with the acl option

To check the latter (replace sdxY appropriately for your root partition):

sudo tune2fs -l /dev/sdxY | grep "Default mount options:"

should return:

Default mount options:    user_xattr acl

Default mount options are set in /etc/mke2fs.conf

They may be overridden, so check:

cat /proc/mounts | grep sdxY

looks something like:

/dev/sdxY / ext4 rw,relatime,errors=remount-ro,data=ordered 0 0

The above is fine, (acl doesn't need to be mentioned) but if it says noacl you need to change it.

You can add the option to default mount options like this:

sudo tune2fs -o acl /dev/sdxY

Or you can add acl to the options for the root partition line in /etc/fstab for example:

UUID=whatever /     ext4    errors=remount-ro,acl    0       1

With ACLs enabled, use setfacl to add permissions for yourself. To give username read and execute permissions on /media/casper (you need execute permission to enter a directory or search its contents):

sudo setfacl -m u:username:rx /media/casper

You can replace username with uid (probably you are 1000 - check with id command)

sudo setfacl -m u:1000:rx /media/casper

to see the ACL permissions you use getfacl like Oli did in his answer

getfacl /media/casper

To remove ACL permissions from a user

sudo setfacl -x u:username /media/casper

To clear all ACL permissions

sudo setfacl -b /media/casper

Note: I cheated and asked a question myself about why there are so many entries in /media. The answer is here

2
  • 1
    Thank you @Zanna: apt-cache policy acl returns ACL is installed and latest. Default mount options mentions acl. cat /proc/mount does not mention noacl. So I guess I need to add the ACL permissions manually now, as for some reason they are unmade. I used the commands you described to give myself rx permissions for the /media/casper directory and I'm glad to say I can access my external media again. Thank you Zanna! Aug 11, 2016 at 11:47
  • Yay, happy you got it fixed :D
    – Zanna
    Aug 11, 2016 at 12:09
3

When you want to give access permission to a Windows drive from Ubuntu

The normal chmod command won't work if it is a Windows NTFS drive.

The following works for me.

Open the file /etc/mtab:

gedit /etc/mtab

Find the drive name in this file (just mouse over on drive for which you are looking for solution, in my case the GUI is showing different name and on mouse over it shows /media/user-name/drive-name)

Now in /etc/mtab:

Search the drive-name in file, and check to which drive your mounted drive is assigned (in my case - /dev/sda4)

Now mount this drive with:

sudo ntfs-3g /dev/sda4 /media/"$USER"

Now I am able to execute my executables, but I won't be able to see contents of drive-name, so I unmounted the drive and mounted it again.

3

Zanna provided a very helpful answer which explains the background.

But there is a simpler way to fix the situation:

  1. Unmount and unplug/eject any and all disks that are currently mounted (inaccessibly) in /media/casper.
  2. Delete the directory: sudo rmdir /media/casper

The next time you attach a USB drive or insert a CD/DVD, Ubuntu will recreate /media/casper with the correct permissions.

(ACLs can get lost e.g. if you backed up the rootfs with tar without the --acls parameter, and later restored it from backup.)

You must log in to answer this question.

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