LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 06:56 PM   #1
Garrett85
Member
 
Registered: Jan 2011
Posts: 332

Rep: Reputation: 6
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, 07:43 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
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 08:08 PM. Reason: Typos, formatting, clarity... I hope!
 
1 members found this post helpful.
Old 08-02-2015, 08:06 AM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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, 08:31 AM   #4
Captain Pinkeye
Member
 
Registered: Oct 2012
Location: The Czech Republic
Posts: 280

Rep: Reputation: 98
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, 10:38 AM   #5
Garrett85
Member
 
Registered: Jan 2011
Posts: 332

Original Poster
Rep: Reputation: 6
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



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 10:23 PM
[SOLVED] mounting usb-stick manually j1alu Debian 10 10-21-2009 12:45 PM
HAL/D-Bus and mounting manually Nylex Slackware 5 07-07-2007 06:15 PM
Manually mounting a USB stick in Suse 9.1 Celettu Linux - Hardware 4 09-14-2004 11:49 AM
fstab, mounting a fat32 partition, need help w/ ownership and all that mackstann Linux - General 2 10-15-2001 02:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:14 PM.

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
Open Source Consulting | Domain Registration