LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-01-2015, 07:56 PM   #1
Garrett85
Member
 
Registered: Jan 2011
Posts: 240

Rep: Reputation: 5
manually mounting and ownership


When I need to manually mount a file I always have to do it with root permissions (I usually just sudo the command). When that happens everything I copy to or from that mount point is owned by root then I have to go run chown so that my current username can make use of anything. How can I do a sudo mount But have the mount point and everything in it owned by my current username rather than root just because I had to use sudo?

I found this in the man pages
users -> Allow every user to mount and unmount the filesystem. This option implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line users,exec,dev,suid).

I'm not sure if the above is what I'm looking for or not. It doesn't show the leading -- in front of the option user so I don't know if I need them and or if it's a command that I need to use the '=' sign with, as in sudo mount user=garrett /dev/sdxxx /DIR

I also found this
uid=n, gid=n
Set the owner and group of all files. (Default: the uid and gid of the current process.)

I also don't know if that's what I'm looking for. Any suggestions? Thanks.
 
Old 08-01-2015, 08:43 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,025
Blog Entries: 1

Rep: Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112
In general, the mount options depend on the type of filesystem being mounted, so there is no one-size-fits-all answer. It is always best to make an entry in the /etc/fstab for commonly mounted devices.

I set up mounts fairly often and still find I must usually review the man pages. Here are some important points to note from man mount:

Code:
The non-superuser mounts.
       Normally, only the superuser can mount filesystems.  However, when 
       fstab contains the user option on a line, anybody can mount the 
       corresponding system.
This is the "user" option you mentioned and is normally an /etc/fstab option as opposed to a mount command line option, hence no -- as you noted. (Although you can specify some options from the command line using the -o option, see man page again...). The user option allows non-superuser mounts, does not directly set the user id, so it makes no sense as a sudo command line option as far as I can tell.

Once /etc/fstab has a line allowing the user to mount the filesystem (i.e. without sudo or being root) any files they create will be owned by that user by default, not by root, which seems to be your main object. Note that this still requires the mount point and mounted paths to have ownerships and permissions that permit the user to access and write to them! But once set these will be persistent to subsequent mounts. Also see man fstab if you haven't already.

You may also make the user the owner of the mounted device... again see man pages.

Too wordy, but the trick for simple cases is to set mount options in /etc/fstab to allow user mounts, and set the directory and file ownerships of the mounted device to allow the desired user access as is normal... all will then work easily.

Last edited by astrogeek; 08-01-2015 at 09:08 PM. Reason: Typos, formatting, clarity... I hope!
 
1 members found this post helpful.
Old 08-02-2015, 09:06 AM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
It also depends on the filesystem being mounted... If it is some variation of fat, then the user performing the mount is assigned ownership.

Normally, this shouldn't be necessary. Most desktops/laptops have udev running that will automatically mount filesystems for the user, and communicate with the users GUI to present them. This happens with USB devices and CD/DVDs.

Linux native filesystems have ownership tracked, and if the user isn't in the authorized list then that user will not have access. The owner/group specification can be made to override that, but it becomes less secure as anyone can mount it. Though if the user mounting it isn't authorized by the uid/gid specification then they still can't access it.
 
1 members found this post helpful.
Old 08-02-2015, 09:31 AM   #4
Captain Pinkeye
Member
 
Registered: Oct 2012
Location: The Czech Republic
Posts: 280

Rep: Reputation: 97
As stated, you can use the "-o" options of the "mount" command. As stated, it depends on the filesystem mounted.

For NTFS, it works quite well:
Code:
mount -o uid=MY_UID /something /somewhere
This causes the mounted device to be owned by user with MY_UID. To get your uid:
Code:
id -u MY_USERNAME
You can change umask as well:
Code:
mount -o uid=1000,umask=0027 /something /somewhere
For other filesystems, it depends.
 
1 members found this post helpful.
Old 08-02-2015, 11:38 AM   #5
Garrett85
Member
 
Registered: Jan 2011
Posts: 240

Original Poster
Rep: Reputation: 5
Thanks all. This is something I'm having to do a lot mainly because I have a few USB sticks that aren't auto mounting any more and I'm having to manually mount them each time. For this problem I don't think I would want to place entries in /etc/fstab just for a few USB sticks but that was still good information that I'll be able to use later. I also had a problem because I did an NFS or SSHFS mount (I can't remember) and moved a lot of my files from one of my Windows computers into my current computer (The Windows computer was booted up with a Mint USB stick). I then had to go and chmod on everything that I had moved because it all belonged to root rather than my username. I'm going to feel dumb asking this but what is umask? Thanks all.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Manually mounting an encrypted partition SolarisZen SUSE / openSUSE 1 02-23-2013 11:23 PM
[SOLVED] mounting usb-stick manually j1alu Debian 10 10-21-2009 01:45 PM
HAL/D-Bus and mounting manually Nylex Slackware 5 07-07-2007 07:15 PM
Manually mounting a USB stick in Suse 9.1 Celettu Linux - Hardware 4 09-14-2004 12:49 PM
fstab, mounting a fat32 partition, need help w/ ownership and all that mackstann Linux - General 2 10-15-2001 03:37 PM


All times are GMT -5. The time now is 06:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration