Link to home
Start Free TrialLog in
Avatar of oakridgeschools
oakridgeschools

asked on

How Do I Mount a USB Drive as a Different User?

I'm trying to mount a USB Drive as a differnet user. It's currently automounting with "root" being both the user and group permissions on the drive. If we run the chown to change the owner (ran it under sudo - so we're running this command as "root"), the command runs fine, but the permissions immediately revert back to "root root" as if we never did anything.

We were thinking that maybe we have to mount the drive as our desired user (fog being that user - we're using Fog Project now for imaging), but we're unsure how to change how Ubuntu (9.04) mounts the drive. Right now it just auto-mounts as root being the owner. Help!

The bottom line is we need to change who owns this external USB drive so we can share it out. Does anybody have suggestions? I am VERY involved in this problem right now, so this should go fast since my responses will be quick.
Avatar of Steven Vona
Steven Vona
Flag of United States of America image

You can put it in your /etc/fstab file.. Something like this:
# //studio/CPavilion      /mnt/cpavilion          cifs     credentials=/root/mounts,uid=500,gid=501,file_mode=0700,dir_mode=0700 0 0


in this case I am using a network drive, but you get the point.

Maybe something like this:

/dev/sdb1                      /mnt/usbdrive           ext2         username=localaccount,password=password

By the way, in my first example up there I am using a credentials file which is a good idea since the /etc/ftsab file is world readable and anyone will be able to see the password.

Here is a helpful link:
How to edit and understand the /etc/ftsab file:

http://www.tuxfiles.org/linuxhelp/fstab.html

Avatar of oakridgeschools
oakridgeschools

ASKER

Ha! Just realized it was you again. I was going to post a link, but I guess you found it. :-)

We're working on this now. Manual mounting is new turf for us. I wonder if there is a way to change the auto-mount options so that it always mounts with the current user being the owner of that drive??

Or will we have to run the above commands every time we attach the device?
As far as I know there is no way to change automount options.  generally speaking if you want settings to stick in linux you have to change a config file somewhere.  I think /etc/fstab file is your only hope! :)  Its simple and once you have it setup you can forget it! :)

Pmount always mounts with root permissions if there isn't a line for the device in /etc/fstab.
Hmmm... It seems we're close, but not quite there. We've edited our FSTAB file. Here's our syntax:
/dev/sdb1/     /media/disk     ntfs     rwx, username=fog, password=password     0     0
The error we get when the drive tries to mount is:
Unable to mount the volume: Cannot obtain lock on /media/.hal-mtab
Any ideas?
Are you trying to mount as root???  What command are you using to try to mount it??

We aren't putting in any command. It's doing that all on its own after we edit FSTAB, and turn the drive back on. I must have missed something?
Ahhh, leave the drive on and reboot.

/etc/fstab is only read at boot, so when you turn the drive on it doesnt know that entry is in fstab.

So turn the drive on and reboot the machine.

If rebooting is not an option try the mount -a command
Well, the device mounted, but still with "root root" permissions. *beats head against wall and starts crying...
Try this in /etc/fstab

/dev/sdb1/     /media/disk     ntfs     rwx, username=fog, password=password,uid=xxx,gid=xxx,file_mode=0777,dir_mode=0777     0     0

use the UID of the user who is mounting the drive.  You can find the UID and gid of the user with the id command

id <username>

file mode and dir mode set the permissions at mounting.  It will make it so that everyone has read/write/execute permissions
OK. We're going to try this. Since this should give everyone permissions to read/write/execute on this drive, do we still need specify "username=fog, password=password" in the syntax?
Thanks so much for the help!
I would keep it there yes.
We used the exact syntax above, and now the drive won't mount. We can open Gpartition and see the drive. It does not load on boot up though, and Gpartition will not allow us to mount the drive. Going back to beating my head against the wall now. You can join me if you wish. Lol...
Oh, and after we saw that it didn't work the first time, we added the "auto" command so we'd be sure to make it auto-mount. Still no dice. Thought I'd better mention that.
What is ther reason why you need to change permissions on that mount point?
Normal user has full access to external disk drives.
Maybe your user don't have enough privileges to automount.

go to System->Administration->User and groups
click on your user then on properties
go to the "User Privileges" tab
Be sure that the "Access external storage devices automatically" option is checked
We are using Fog Project, and we're getting denied permission to the disk via TFTP. It is saying "Permission Denied." We know our fog authentication works correctly, and has access to do whatever it needs to the file system becuase we were originally using the root drive as the storage for our images. We figured since the only variable was adding our USB drive, that the USB drive must not be allowing read/writes. Thus, we tried changing the owner of files on that drive, and the drive itself. We noticed that not only could we not see the user permissions using the GUI, when we used the terminal to change permissions, the terminal would accept the command, apparently execute, but the permissions remained unchanged.
We checked the user privileges, and it is checked to auto-mount. The drive auto-mounts fine if we don't modify the FSTAB file. It's only when we use the above syntax in the FSTAB file that the drive refuses to properly mount. Like I said, we can see it, but we can't actually mount it. I suppose we could trying mounting it using a command line? We tried Gpartition, (which we used successfully before to mount the drive), but it won't let us mount now.
Is the "Access external storage devices automatically" option checked for the user?
Sorry, yes. It was, and still is.
ASKER CERTIFIED SOLUTION
Avatar of Steven Vona
Steven Vona
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
BTW if the drive is blank you can format it in ext2 or 3 and get around all of this easily.  These ext file systems are much more efficient than NTFS.
We reformatted the drive to ext3 since there wasn't anything important on it.

I changed the line in my fstab file and mounted the drive. Just to be exact, I used your exact line above. Here is the output of ls -l...

total 4
drwxr-xr-x 3 777 root 4096 2009-07-08 13:32 drobo

Looks like we may be getting somewhere? :-)
Ok, so first of all you did not have to name the mount point drobo... Thats just what I call mine since I have a drobo connected there. :)

Either way you should now be able to set the permissions without any problems either by the chmod command or via the gui.

That worked great! Thank you! I feel like I'm in control of Linux box again!
Great, I am glad you got this solved, it was a long road! :)

NTFS doesnt play nicely with linux as linux has NO understanding of NTFS permissions.  Good luck!
Thanks! Now to get Fog to recognize that, yes, it does have permission to write to this drive. Lol... That's another post though.