Solved

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

Posted on 2009-07-08
28
1,321 Views
Last Modified: 2013-12-06
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.
0
Comment
Question by:oakridgeschools
  • 12
  • 12
  • 4
28 Comments
 
LVL 23

Expert Comment

by:savone
Comment Utility
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
 
LVL 23

Expert Comment

by:savone
Comment Utility
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
 
LVL 1

Author Comment

by:oakridgeschools
Comment Utility
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
 
LVL 23

Expert Comment

by:savone
Comment Utility
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
 
LVL 14

Expert Comment

by:fmarzocca
Comment Utility
Pmount always mounts with root permissions if there isn't a line for the device in /etc/fstab.
0
 
LVL 1

Author Comment

by:oakridgeschools
Comment Utility
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
 
LVL 23

Expert Comment

by:savone
Comment Utility
Are you trying to mount as root???  What command are you using to try to mount it??

0
 
LVL 1

Author Comment

by:oakridgeschools
Comment Utility
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
 
LVL 23

Expert Comment

by:savone
Comment Utility
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
 
LVL 23

Expert Comment

by:savone
Comment Utility
If rebooting is not an option try the mount -a command
0
 
LVL 1

Author Comment

by:oakridgeschools
Comment Utility
Well, the device mounted, but still with "root root" permissions. *beats head against wall and starts crying...
0
 
LVL 23

Expert Comment

by:savone
Comment Utility
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
 
LVL 1

Author Comment

by:oakridgeschools
Comment Utility
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
 
LVL 23

Expert Comment

by:savone
Comment Utility
I would keep it there yes.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 1

Author Comment

by:oakridgeschools
Comment Utility
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
 
LVL 1

Author Comment

by:oakridgeschools
Comment Utility
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
 
LVL 14

Expert Comment

by:fmarzocca
Comment Utility
What is ther reason why you need to change permissions on that mount point?
Normal user has full access to external disk drives.
0
 
LVL 14

Expert Comment

by:fmarzocca
Comment Utility
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
 
LVL 1

Author Comment

by:oakridgeschools
Comment Utility
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
 
LVL 14

Expert Comment

by:fmarzocca
Comment Utility
Is the "Access external storage devices automatically" option checked for the user?
0
 
LVL 1

Author Comment

by:oakridgeschools
Comment Utility
Sorry, yes. It was, and still is.
0
 
LVL 23

Accepted Solution

by:
savone earned 500 total points
Comment Utility
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
 
LVL 23

Expert Comment

by:savone
Comment Utility
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
 
LVL 1

Author Comment

by:oakridgeschools
Comment Utility
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
 
LVL 23

Expert Comment

by:savone
Comment Utility
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
 
LVL 1

Author Closing Comment

by:oakridgeschools
Comment Utility
That worked great! Thank you! I feel like I'm in control of Linux box again!
0
 
LVL 23

Expert Comment

by:savone
Comment Utility
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
 
LVL 1

Author Comment

by:oakridgeschools
Comment Utility
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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now