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.
LVL 1
oakridgeschoolsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

savoneCommented:
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

0
savoneCommented:
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

0
oakridgeschoolsAuthor Commented:
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?
0
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

savoneCommented:
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! :)

0
Fabio MarzoccaFreelancerCommented:
Pmount always mounts with root permissions if there isn't a line for the device in /etc/fstab.
0
oakridgeschoolsAuthor Commented:
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?
0
savoneCommented:
Are you trying to mount as root???  What command are you using to try to mount it??

0
oakridgeschoolsAuthor Commented:
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?
0
savoneCommented:
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.

0
savoneCommented:
If rebooting is not an option try the mount -a command
0
oakridgeschoolsAuthor Commented:
Well, the device mounted, but still with "root root" permissions. *beats head against wall and starts crying...
0
savoneCommented:
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
0
oakridgeschoolsAuthor Commented:
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!
0
savoneCommented:
I would keep it there yes.
0
oakridgeschoolsAuthor Commented:
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...
0
oakridgeschoolsAuthor Commented:
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.
0
Fabio MarzoccaFreelancerCommented:
What is ther reason why you need to change permissions on that mount point?
Normal user has full access to external disk drives.
0
Fabio MarzoccaFreelancerCommented:
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
0
oakridgeschoolsAuthor Commented:
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.
0
Fabio MarzoccaFreelancerCommented:
Is the "Access external storage devices automatically" option checked for the user?
0
oakridgeschoolsAuthor Commented:
Sorry, yes. It was, and still is.
0
savoneCommented:
OK I have a USB drive connected and this is what I have in my fstab for it:

/dev/sdb1               /mnt/drobo              ext3    noatime         0 0


Of course its ext3 not ntfs, but for the hell of it lets mount it this way (change ext3 to ntfs).


do a mount -a and then do a long directory listing with the following command so we can see the permissions:

ls -l



0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
savoneCommented:
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.
0
oakridgeschoolsAuthor Commented:
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? :-)
0
savoneCommented:
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.

0
oakridgeschoolsAuthor Commented:
That worked great! Thank you! I feel like I'm in control of Linux box again!
0
savoneCommented:
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!
0
oakridgeschoolsAuthor Commented:
Thanks! Now to get Fog to recognize that, yes, it does have permission to write to this drive. Lol... That's another post though.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Distributions

From novice to tech pro — start learning today.