How to read and write to Windows NTFS drives as any user

ntfs

So you have a Windows hard drive using the NTFS partition type. The good news is that most Linux distributions these days can read and write to it automatically without as much as a config change. It automatically sees the partition and mounts it

That’s great, but what if you have a one-user Linux box and you want every app on your Linux box to be able to use the files on that partition, not just your user account? I recently ran into this problem when I wanted to share an external NTFS formatted USB drive with my Plex Media Server. The Plex media server runs as the pseudo user ‘plex’. My own user account obviously is not named ‘plex’ and therefore it refused to see any of my music and movies on the USB hard drive, as the files on the hard drive were ‘owned’ by my user account, not ‘plex’.

How to get around this problem? Well, provided you are not worried about sharing everything on that drive with all (or some) of the other real or pseudo users on the machine, then you can create a user group, say called ‘ntfs’, and have all the users you want to read and write to the drive in that group. Here’s how you do it from the command line:

sudo groupadd ntfs
sudo usermod -a -G ntfs YOUR_USER_NAME
sudo usermod -a -G ntfs USER_NAME_OF_ANY_OTHER_USER_YOU_WANT_TO_ACCESS_THE_DRIVE

So the above has created the group ‘ntfs’ and added your own username as well as any others you want to that group.  The output of the first command should look like this:

The output should look something like this:

Adding group `ntfs' (1004)... 
Done

Take note of that number in brackets. That’s your GID (group ID number).

Next, let’s make the location to mount the partition on your drive. Assuming you are running Ubuntu, this will be in /media, but it can be anywhere you like, for example /mnt, or even under / – just as long as all the users you added to the group can already access that folder.

sudo mkdir /media/windows
sudo chgrp ntfs /media/windows

Now it’s time to edit the file system table (fstab). Don’t worry – that’s not as scary as it sounds, it’s just a text file which contains a list of the partitions the Linux system should mount on startup.

sudo nano -w /etc/fstab

Assuming that Windows is installed on the first drive, and first partition we use /dev/sda1. If your windows drive is on another drive in your PC, say the second drive, and it’s the third partition, it would be /dev/sdb3 and so on. You can check to see if you got the right drive and partition number with the fdisk tool.

add the following to the bottom of the /etc/fstab file:

/dev/sda1    /media/windows    ntfs-3g    auto,gid=1004,unmask=0002    0 0
Remember to keep the spaces  after each item as they instruct the system to read each option. Don’t forget those two zeroes at the end of the line either!

 

Explanation: /media/windows is the new location where the partition is mounted, so when you visit it in your file browser (or with ls at the command line), you’ll see the files in /media/windows. The option ntfs-3g is telling the mount program that this is a ntfs partition and we will use the 3g driver to write to it. The next option tells the system to mount the partition automatically at startup and finally the gid/umask information allows all users in the ntfs group to read and write to it.  Note we specified the gid of 1004 which is the gid we were given by the groupadd command. If you don’t match this number, you and any other user in the newly created ntfs group won’t be able to read and write to the /media/windows folder.

Question MarkMake sure that the gid= value is the same as whatever you saw when you used the groupadd command earlier.

Save the fstab file and exit the editor. To test it works properly, simply type:

sudo mount -a

This command reads the contents of the newly updated fstab and as long as it is correct, it will mount the windows partition in /media/windows (or wherever you specified to mount it). When you reboot your machine the partition should automatically be mounted so you shouldn’t need to do anything!

Enjoy!

Be the first to comment on "How to read and write to Windows NTFS drives as any user"

Leave a Reply