Mounting volume/partition with permissions for user
What is the best practice for this situation, and what are the implications of each approach?
3 Answers 3
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:
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.
Mount cifs Network Drive: write permissions and chown
I have access to a cifs network drive. When I mount it under my OSX machine, I can read and write from and to it. When I mount the drive in ubuntu, using:
sudo mount -t cifs -o username=$,password=$ //server-address/folder /mount/path/on/ubuntu
I am not able to write to the network drive, but I can read from it. I have checked the permissions and owner of the mount folder, they look like:
4.0K drwxr-xr-x 4 root root 0 Nov 12 2010 Mounted_folder
chown: changing ownership of `/Volumes/Mounted_folder': Not a directory
When I descend deeper into the network drive, and change the ownership there, I get the error that I have no permission to change the folder´s owner. What should I do to activate my write permission?
You can also use the noperm mount option similarly stated in my answer to this question: unix.stackexchange.com/a/375523/16287. This will give all users read and write access to the CIFS mount.
3 Answers 3
You are mounting the CIFS share as root (because you used sudo ), so you cannot write as normal user. If your Linux Distribution and its kernel are recent enough that you could mount the network share as a normal user (but under a folder that the user own), you will have the proper credentials to write file (e.g. mount the shared folder somewhere under your home directory, like for instance $HOME/netshare/ . Obviously, you would need to create the folder before mounting it).
An alternative is to specify the user and group ID that the mounted network share should used, this would allow that particular user and potentially group to write to the share. Add the following options to your mount: uid=,gid= and replace and respectively by your own user and default group, which you can find automatically with the id command.
sudo mount -t cifs -o username=$,password=$,uid=$(id -u),gid=$(id -g) //server-address/folder /mount/path/on/ubuntu
If the server is sending ownership information, you may need to add the forceuid and forcegid options.
sudo mount -t cifs -o username=$,password=$,uid=$(id -u),gid=$(id -g),forceuid,forcegid, //server-address/folder /mount/path/on/ubuntu
Mount doesn’t give write permission to user
it does mount correctly, but then only root seems to have write permissions. How can I give write permissions to my user as well?
Is this a permanent thing? If so, you can add the drive to your /etc/fstab with the user option activated.
3 Answers 3
This is normal behavior — mount doesn’t give write permissions at all. The write permissions are controlled by the permissions bits on the directory in the filesystem (i.e. after it’s mounted). To manage who can read and write from/to this filesystem, just use the normal chown and chmod tools.
Why does mount change the ownership of the directory? Initially this a directory was owned by my user with write permission on it.
@Grzenio mount temporarily overlays the directory a with the / directory of the filesystem that has been mounted. a ‘s owner, its permissions, even all of its contents, are all hidden. When you unmount the filesystem, you can access a just as it was before.
The directory a prior to the mount is a completely different item than the filesystem at a after the mount.
«mount doesn’t give write permissions at all.» For the sake of completeness, some filesystems (the ones which don’t support Unix permissions, e. g. fat and vfat) may be provided uid , gid and some ?mask options through mount to control access.
If you just need to view files, and the mounted filesystem is read-only, just open a GUI file manager as root , as I mention here.
As Mark Plotnick said, mount just overlays a directory in your system with the contents of / on the attached drive.
To circumnavigate this and as an expansion to John’s answer, you can try
depending on your preference. The command will change all files in a to give you RW permissions.
Alternatively, if ls -l reports that root is the owner:
would make you the owner of all the files in a .
chmod and chown with -R can mess up some intentional permissions modifications on files, so do exercise caution when executing such commands.
Shouldn’t that be chmod -R -rwxrw-rw- a ? (with a final — to say unprivileged users can’t execute the file.)
If the mounted filesystem is read only, such as a MacBook Apple Filesystem (APFS) mounted with apfs-fuse on an Ubuntu LiveUSB, you can’t use chown to change the owner. In that case, just open a root file manager window and view the files through that.
# the default Ubuntu file manager: nautilus sudo nautilus # the pretty one (https://askubuntu.com/a/1173861/327339): nemo sudo add-apt-repository universe sudo apt update sudo apt install nemo sudo nemo
How can I automatically set write permissions on mounting a usb drive in linux?
When I mount an external usb drive on linux (CentOs4), the permissions are by default set to read-only. Since there are multiple users on the computer who need to use the external drive, I want everybody to have rw permission for the entire drive. I also want them to be able to mount the drive if the computer has accidentially been shut down. They can use sudo mount to mount the drive, but this will only give them read permission, and I obviously don’t want to allow sudo chmod . Is there a default setting that I can change so that every new external usb disk automatically gets rw permissions?
3 Answers 3
To enable everyone rw access, the key is umask=0 option to mount command.
sudo mount -o umask=0,uid=nobody,gid=nobody /dev/something /mnt/somewhere
umask=0 is enough, uid and gid just for sake of clarity, so you don’t see more ‘root’ owners than necessarily.
@Tom’s answer (writing /etc/fstab entry) will allow you to skip sudo and if you write umask=0 as additional option there, you’ll get best of both worlds:
/dev/something /mnt/somewhere auto users,noatime,umask=0 0 0
and everyone has access to all files.
Here’s technical note, if you wish to know details:
As man mount says, ‘umask=0’ will ensure that no additional rules apply to files access mode. For FAT filesystems (which are most widely used on USB disks), there’s no access mode stored. But your current process has some umask value set, you can see it if you run just umask in terminal. mount uses that as default and removes access mode of your umask value from all files on mounted disk. Most widely used umask values are (octal) 022 — no group and other write, and 027 — no group write, no any other access.
I get an error with ‘bad option’ if I add umask=0 0 0 as an entry in fstab. Does the umask -entry need to be the last entry? What does the managed=0 0 0 entry do that is currently last?
FWIW, the umask option is a VFAT-only option, i.e. the solution helps as long as the USB memory is uses the VFAT filesystem (which did not happen to be my case).
Thank you. But I had to alter it in order to make it work: sudo mount -o umask=0,uid=nobody /dev/something /mnt/somewhere It only works without setting the gid-parameter.
Add an entry to /etc/fstab. Here is an entry that I added just a few hours ago for my Seagate USB drive:
UUID=4ACC734ECC733375 /media/Linux ext3 errors=remount-ro,defaults,users,noatime,nodiratime 0 0
The key here is the «users» entry that allows users to mount and unmount the drive.
Edit: this works for specific drives — I don’t know if it can be enabled for all drives with one entry.
Type mount . This will give the current place it is at. Here is my output.
rick@rick-Main ~ $ mount /dev/sda4 on / type ext4 (rw,errors=remount-ro) proc on /proc type proc (rw,noexec,nosuid,nodev) sysfs on /sys type sysfs (rw,noexec,nosuid,nodev) none on /sys/fs/cgroup type tmpfs (rw) none on /sys/fs/fuse/connections type fusectl (rw) none on /sys/kernel/debug type debugfs (rw) none on /sys/kernel/security type securityfs (rw) udev on /dev type devtmpfs (rw,mode=0755) devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620) tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755) none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880) none on /run/shm type tmpfs (rw,nosuid,nodev) none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755) none on /sys/fs/pstore type pstore (rw) /dev/sda6 on /media/DATA1 type vfat (rw,uid=1000,utf8,umask=077) binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev) systemd on /sys/fs/cgroup/systemd type cgroup (rw,noexec,nosuid,nodev,none,name=systemd) gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,user=rick) /dev/sdf1 on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime)
The last is my usb drive automouunted by Linux Mint.
sudo mount -t vfat /dev/sdf1 /media/usb0 -o rw,users,umask=0