How do I give multiple users access to a Windows NTFS partition?
I have USB hard-drive connected to my Ubuntu (11.04) machine. Every time I reboot the computer and login it mounts the hard-drive. Since the disk has NTFS on it, Linux assigns some user to be the owner of the files on the disk. So all files on the disk appear owned by one user and only that user can see the files.
I use two user accounts on my computer and often switch between them. Once I switch to other user account, I can no longer access contents of the disk because it is owned by my first user account. Is there anything can be done about it except mounting it via /etc/fstab?
Thanks.
Mounting with specific permissions
There is. Put both users in a group together. Then use that group's to set the gid=
option and and mount your disk with the permissions you want it to have. You can control permissions with umask=
, fmask=
and dmask=
options in the mount command. Here is an example:
mount -O dmask=007,fmask=117,gid=46,uid=1000 /dev/sdc1 /media/winhdd
These options can also be used in /etc/fstab
like this: UUID=7258CB9858CB598D /media/win ntfs rw,auto,user,exec,nls=utf8,dmask=007,fmask=117,gid=46,uid=1000 0 2
.
Avoiding fstab - automounting a specific disk with udev
I imagine you want to avoid fstab because the disk it not always connected on boot. If you wish to avoid fstab use a udev rule. Udev can automatically mount (and prevent Ubuntu from automounting) when the disk is connected. A rule for that may look like this:
# In /etc/udev/rules.d/70-usb-winhdd-mount.rules
KERNEL=="sd?[0-9]", ATTR{removable}=="1", ATTRS{serial}=="UA04FLGC", ACTION=="add", RUN+="mount -O dmask=007,fmask=117,gid=46,uid=1000 /dev/%k /media/winhdd"
You will need to identify the disk by it's properties. In my example I did this by ATTRS{serial}=="UA04FLGC"
. I described how to do this in another question. The naming and location of the rules files is described there too.
Give all removable disk those properties
If you want to do this with all removable disk - not just that particular one, simply leave out the serial part and be sure to assign a unique mountpoint (counting them, creating from serial, %-symbol of udev or other method). Also as stated elsewhere ENV{mount_options}="$env{mount_options},dmask=007,fmask=117,gid=46,uid=1000"
could be an option for mounting all removable disks with certain permissions/onwership.
Useful information you might already know:
Creating a group and adding users
Those are the shell commands to create a group named 'winhdd' and add a user named 'confus' to that group:
groupadd winhdd
usermod -a -G winhdd confus
Finding out the group id
You can find the group ids of all the groups on your system in a file called /etc/group
. The entries there look like winhdd:x:4:confus,narur,joe
where 'confus', 'narur' and 'joe' are the user names belonging to that group, 'adm' is the group's name and '4' the group id, you're looking for. In /etc/groups
you can also check if adding the users to your group was successful. The command getent group winhdd
would show the line with information about the group. The id
command gives you your group id, user id and the names and ids of all groups you belong to.
Setting umask-like options
You'll want to set dmask=
to a sensible value allowing you at least to execute (=access) directories. fmask=
is the option for file permissions.
dmask=007,fmask=117,gid=46,uid=1000
allows the owner that is user number 1000 (first digit in the masks) and the the members of group number 46 (second digit in the mask) to read and write and files on the disk. Other users have no rights to do anything (hence third digit in the masks - the 7). Here are the mask values:
7 – no permissions 6 – execute only 5 – write only
4 – write and execute 3 – read only 2 – read and execute
1 – read and write 0 – read, write and execute