80

I have an Ubuntu 10.04 box with an EXT4 partition. This partition is set to automatically mount in /etc/fstab. For the purposes of this post, we'll call it: /media/foo.

Unfortunately, only root can create/delete files/directories on the root filesystem of foo. For other users to perform file/io on this volume, root needs to create a directory and chmod the permissions to others.

I would like to mount the volume such that anybody would be able to read/write to the volume without the need of root to chmod.

Below is my fstab entry:

/dev/sda8    /media/foo    ext4    rw,user,exec 0 0

The entry originally had defaults instead of rw,user,exec. I added the additional entries, namely, rw so any user can read/write.

Unfortunately, the fstab entry does not work. It mounts fine, but it still requires root to intervene.

And, just in case anybody asks, simply running: chmod -R 777 * on /media/foo as root does not work.

8 Answers 8

57

The mount option user only allows the filesystem to be mounted by any user. The rw option makes the filesystem not readonly. You will have to use permissions to make the parent directory writeable.

chmod 777 /media/foo

The chmod command you show only affects the existing files within /media/foo.

5
  • 3
    What is the best place in Ubuntu to add this command at startup? Aug 18, 2014 at 13:35
  • @IvanBalashov: You can use an @reboot entry in /etc/crontab among other possibilities. Aug 18, 2014 at 15:19
  • 4
    @DennisWilliamson Thanks. I've put it into /etc/rc.local if it makes any difference. What bugs me overall about this though, is that it really should be configured in fstab. If not, mount point can change, and scripts have to change too, maintenance hell. Aug 18, 2014 at 16:16
  • Wow, i must start to guess those things :D thank you a lot.
    – m3nda
    May 29, 2015 at 15:11
  • 2
    Agree with the chmod, but add a: chmod +t /media/foo to enable users to create their own subdirectory Mar 10, 2017 at 11:25
45

I think it would be simpler to change the fstab entry to:

/dev/sda8    /media/foo    ext4    rw,user,exec,umask=000 0 0

umask=000 means that anyone can read, write or execute any file or directory in foo. The usual default is 022, which means that users cannot write.

4
  • 49
    umask is only an option for ntfs/vfat partitions. mount will not like umask on an ext filesystem.
    – Daniel
    Sep 14, 2012 at 1:07
  • 1
    I think a better aproach would be rw,user,exec,mode=1777
    – Binar Web
    Dec 23, 2020 at 9:37
  • 2
    On my machine (Arch Linux), ext4 recognizes neither umask=000 nor mode=1777...
    – nyanpasu64
    Feb 20, 2022 at 17:26
  • works a treat with a USB memory-stick on Ubuntu when chmod 777 did not ; going to fstab and adding =000 really did
    – shantiq
    Dec 25, 2022 at 9:42
12

I had the same problem on openSUSE, but I think the solution can apply to this too. All the users I want to share the mounted filesystem belong to the same primary group: users

I have the following line in my fstab:

/dev/<partition> <mount_point>          ext4       rw,acl       0 0

and I ran the following commands:

sudo chgrp -R users <mount_point>
sudo setfacl -d -m g::rwx <mount_point>

so that newly created files or directories get those permissions. This implies that you have the acl package installed.

1
  • 1
    If it is an encrypted directory say /home will this be mounted in the /etc/crypttab? Feb 5, 2017 at 18:17
4

Well for one thing, you want to make sure the directory of /media/foo itself is writeable. If it isn't already, run the following command:

chmod +w /media/foo

Remember, star only applies to the visible contents of the directory, not the directory itself nor any files that are not visible.

3

I want to capture everything about this in a single answer, so here it is:

  1. The accepted answer is the correct answer: chmod 777 /media/foo.
    While it might seem inelegant, because ideally we would want to set the right permissions in Fstab itself. The second most-voted answer suggests doing this using the umask option (and from some other sources even uid/guid options) but I believe EXT filesystems do not suppport these options. They are mount options for the FAT filesystem, as you can very well see here: man mount.

  2. Running the chmod command every time on start up is unnecessary.
    We are modifying the permissions of the mount point /media/foo and not the permissions of the device /dev/sda8. The directory /media/foo is just a simple Linux directory, and directory permissions are persistent and need not be set every time on boot.

  3. Doing a chmod +t is unnecessary.
    One of the comments in the accepted answer suggests adding a +t to the chmod command. The +t option "prevents unprivileged users from removing or renaming a file in the directory unless they own the file or the directory". As we work as normal users in the /media/foo directory, we will be owning all the sub-directories and files we create. I have tested this without using the -t option and it works fine.
    (But of course, if you are mounting a non-empty EXT filesystem with existing files belonging to other users, you might need this option.)

Summarizing, this is how my /etc/fstab entry looks like:

/dev/disk/by-uuid/2ea4247b-8d8b-41ef-aef8-5185fc252cf6 /media/emmc ext4 defaults 0 2

and the only command I ran once is:

sudo chmod 777 /media/emmc
1

A few years ago I have set the mount point's group to the plugdev group, added the user to that group. This way, by creating new groups, it is possible to give permissions on a per user basis. For home usage, it's enough to set mount point permissions to others: read/write/execute as written above.

I did it with 'sudo nautilus &' in terminal and right click -> properties -> rights, but any other file manager running as root would be fine.

1
  • The group and permissions of the mount point disappears when mounting something on it and is replaced by the group and permissions of the root directory of the mounted disk as long as it is mounted. The mount point's properties reappear when unmounting.
    – Juergen
    Mar 24 at 15:41
1

Try,

sudo setfacl -R -d -m u::rwx,g::rwx,o::rwx <mount_point>
0
1

Other way is before mounting it, you can give required ownership to the mount point. So that when you mount it, required user will have its ownership.

2
  • sometimes the simplest answers are the best, cheers
    – alchemy
    Oct 10, 2022 at 2:21
  • The ownership of the mount point disappears when mounting something on it and is replaced by the ownership of the root directory of the mounted disk as long as it is mounted. The mount point's properties reappear when unmounting.
    – Juergen
    Mar 24 at 15:39

You must log in to answer this question.

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