17

A volume intended for use by my user was created at OS installation with root ownership and my user lacks write permissions.

Some solutions I've read about include:

  • changing ownership of the mount point with chown
  • adding group write permissions with chmod
  • adding user or users mount option in /etc/fstab.

What is the best practice for this situation, and what are the implications of each approach?

1
  • Love it when your exact question has been asked (and answered)!
    – sonyisda1
    Commented Oct 25, 2020 at 18:33

5 Answers 5

23

If it's in /etc/fstab, then it will mount at boot.  As only root has write permissions, you'll need to modify it so that the user has those permissions.  The best way is:

chown -R user /mnt/point

where user represents your user name (or user ID), and, obviously, /mnt/point represents the mount point of your file system.  If the root group has write permission as well and you want another group to have it then you can use:

chown -R user:group /mnt/point

If the root group doesn't have write access, then you can use chmod next:

chmod -R 775 /mnt/point

That will give write permission to the group if it's not there and read and execute to everyone else. You can modify the 775 to give whatever permissions you want to everyone else as that will be specified by the third number.

To better cover what you asked in your comment below:

You can add the user option to /etc/fstab, but that only allows the file system to be mounted by any user. It won't change the permissions on the file system, which is why you need chown and/or chmod. You can go ahead and add the user option so that a regular user without sudo can mount it should it be unmounted.

For practicality, the best option here is chown as it gives the user the needed permissions instantly. The chmod command can be used afterwards if the permissions need to be modified for others.

4
  • The chown approach works, but requires authentication to mount (if unmounted after boot). I presume adding user or users to the fstab mount options would allow user mounting without authentication? What are the practicality and security considerations of each approach?
    – adatum
    Commented Jul 13, 2018 at 2:24
  • @adatum See my update. Commented Jul 13, 2018 at 6:23
  • 2
    Do you have to run chown after mounting the partition? My mount point began as owned by a non-root because I logged in as e.g. bobby and created /home/bobby/mnt/usb. ls -l confirmed bobby's ownership. But, after mounting, ls -l gave root for owner and group. I then had to 'chown -R bobby ~/mnt/usb' as mounted; only then did bobby get write permission. Is this the expected outcome or peculiar to my system (OpenWrt)? I believe it would improve the answer to specify whether in general the chown method is expected to work on a mount point as yet unmounted.
    – user480036
    Commented Aug 13, 2021 at 3:40
  • chown/chmod can be used to let me do one thing, one time, that I need to do to a file/drive that never had any business being owned by root in the first place, but it has to be redone constantly, as the effects are not persistent. How do I set up a drive that is mounted at boot-up, such that the entire drive (including all contents) stays owned by the primary user, and permissioned to all users, even after I do things like rebooting, or writing to it from a program running as root? Commented Apr 21, 2023 at 18:38
3

I was doing chown -R user /mnt/point but it was not working. It turned out that I first need to umount and then set the permission

umount /mnt/point
chown -R user /mnt/point

Now mount or restart (if you have the /etc/fstab entry).

0

If mountpoint owner is still root, then it worked to set mode=0755,uid=1000 in 4th column of the fstab. uid is the number returned by id command. I am unsure if it would work to use the username directly instead of a number.

0

For a pendrive, a possibility is to add a label with gparted; after that, when you plug the usb, it will be in /media/username/label_added.

If you use sudo mount /dev/sdxx /media/username/destination, even if you own that destination, permissions will change to root

0

You can add to mount command: -o uid=<user id>,gid=<group id>.

You must log in to answer this question.

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