Showing posts with label Permissions. Show all posts
Showing posts with label Permissions. Show all posts

Saturday, December 26, 2009

Permissions, Samba Sharing an External NTFS drive, and fstab

For my first post on this blog I wrote about setting up samba shares for my printer and external hard drive.  When I wrote that entry, I thought I finally succeeded in sharing both devices.  I was disappointed to learn that my solution was temporary, and my external USB hard drive was still unable to be shared with my wife's Windows XP machine.

After hours and hours of pursuing the solution to this problem like Captain Ahab come to life, I started to realize that my problem wasn't anything to do with Samba itself, but the permissions that were automatically assigned to my external hard drive upon its mounting.  Every time I looked at the extended information given by the ls -l command in my /media directory, I saw the following:

drwx------ 1 inkhorn inkhorn 4096 2009-12-06 18:24 backup

In other words, my external hard drive was mounted so that I personally would have read, write and execute access to the drive, that I could mount and unmount it, but nobody else could access my drive in any way at all.

From googling my problem, I learned that if you modify the fstab (file system table) file in the /etc directory, you can change the permissions linux assigns to your hard drive when mounting it.  I found numerous message board postings with examples of how to set up an entry for your hard drive in the fstab file, but none of them helped for very long.  Finally I found a web page that described a program available to Ubuntu users called pysdm (Python Storage Device Manager) that provides a GUI allowing the user to set permissions for any attached storage devices.





As you can see above, it displays all connected partitions and provides an Assistant button that allows you to choose your mounting options intelligently.  In my case, without having a USB stick connected first, my external hard drive shows up as partition sdb1, or /dev/sdb1. 





When you click on the Assistant button, you're brought to the above Select options window.  Most of these options were already set as enabled when this window popped up.  I think the only option here that I changed was to enable Allow a user to mount and unmount the file system.





I then found an option I thought might be important in the Miscellaneous tab.  I enabled the option above labelled This file system requires network.  So, I pressed OK, then at the main window I pressed the Apply button.  There was one catch however: the line that it automatically entered into my /etc/fstab file linked the partition to the mounting point, not the device itself.  See the fstab entry below:

/dev/sdb1    /media/backup    ntfs    nls=iso8859-1,_netdev,umask=000,user,owner  0  0

In other words, what this entry in my fstab file says is that any time partition /dev/sdb1 comes online, mount it to /media/backup; even if /dev/sdb1 is my USB stick, and not my external hard drive!  You see what I mean?

This is where what's called the UUID comes in handy.  The UUID is an alphanumeric sequence that uniquely identifies each connected storage device independently of the partition assigned to that device.  After all, if I connect my USB stick and then my external hard drive, it's my USB stick that would show up as partition sdb1, while my
external hard drive would show up as partition sdc1.  In order to make sure that it's my external hard drive that gets mounted as /media/backup and not my USB stick, I had to replace /dev/sdb1 with the UUID.  To find out the UUID of a connected device, go to the terminal and type in sudo blkid.  Here's the output on my terminal:

inkhorn@inkhorn-laptop:/media$ sudo blkid
/dev/sda1: UUID="2fb4ca03-eca7-41f8-9767-bbfaf88a1890" TYPE="swap"
/dev/sda2: UUID="34B836C6B8368700" LABEL="S3A6134D002" TYPE="ntfs"
/dev/sda5: UUID="ece79ff2-c123-4a72-80a9-c187b2cfd785" TYPE="ext4"
/dev/sdb1: UUID="010C7CC23301CA6C" LABEL="backup" TYPE="ntfs"

So, I opened up the fstab file again and replaced /dev/sdb1 with UUID=010C7CC23301CA6C.  I then saved the fstab file, restarted, and VOILA!!!  My Samba share for my external hard drive is finally accessible from my Wife's Windows XP machine!




If you want to install pysdm on your Ubuntu system, type the following in your terminal:

sudo apt-get install pysdm

Then you can access it through the following menu items: System > Administration > Storage Device Manager.