LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Changing ownership of partition and USB key (https://www.linuxquestions.org/questions/linux-newbie-8/changing-ownership-of-partition-and-usb-key-282654/)

a thing 01-26-2005 07:46 PM

Changing ownership of partition and USB key
 
Is there any way to change the owner of a partition or USB flash drive to a non-root user? I'd be nice if I didn't have to log into root to use those.

Dark_Helmet 01-26-2005 07:52 PM

Nothing so drastic is necessary :)

Open your /etc/fstab file in an editor, and add the "user" option to all the devices that you would like to allow regular users to mount. For instance, here is a line from my /etc/fstab for my USB pendrive:
Code:

/dev/sda1      /media/pendrive  vfat    noauto,rw,user          0    0
Your USB drive will likely be the same device unless you have SCSI disks in your system; in which case, you's probably be familiar enough to know what to change. Save the file, and then regular users should be able to mount and unmount those devices at will.

m_yates 01-26-2005 08:48 PM

I did the same thing as Dark_Helmet. One other thing, you won't be able to mount the drive as a regular user (the command mount /dev/sda1 will only work as root). Instead, you need to do:
Code:

mount /media/pendrive
as regular user to mount it.

Dark_Helmet 01-26-2005 09:19 PM

m_yates:
Really? It won't let you execute mount /dev/sda1 as a regular user? That's a bit odd if I may say so. My system will allow a regular user to mount using either the device itself or the mountpoint. I just double-checked and that the user I tested with isn't in any special groups or anything like that. I can't say anything comes to mind about why you're seeing that behavior.

makuyl 01-27-2005 02:34 AM

You should be able to do mount /dev/sda1 as user, but probably can't give mountoptions like: mount -t vfat /dev/sda1

jschiwal 01-27-2005 03:00 AM

For vfat partitions, you can use the 'uid=' and 'gid=' options. For pendrives however, they are usually mounted dynamically by the hotplug system, rather than having an entry for the device in /etc/fstab.

Dark_Helmet 01-27-2005 03:13 AM

Quote:

Originally posted by jschiwal
For pendrives however, they are usually mounted dynamically by the hotplug system, rather than having an entry for the device in /etc/fstab.
True, but if the pendrive is the only USB device that's being used (or used frequently), then adding an entry in /etc/fstab isn't going to hurt anything.

Also, if the system is using udev (2.6 series kernel), udev can be configured to assign a specific device to a specific designation. For instance, assigning the pendrive to /dev/sda1. I haven't done this myself (I fall into the pendrive-is-the-only-device category), but it makes adding an entry in /etc/fstab very useful in this case as well.

An sda1 entry may not work for 100% of the people, but it's probably useful for a large group.

jschiwal 01-27-2005 05:37 PM

I agree with dark_helmets advice. The direct answer is to use the 'uid' and 'gid' in the fstab entry to change the ownership and group ownership of the pendrive. If you don't remove the drive, then an fstab entry is great, but if a device isn't present, and if the /etc/fstab entry results in the partition being mounted during boot, then the computer won't finish booting because the device isn't present.

So adding the 'user' option would be a good idea. It may be an idea to include a test for the device in the users ~/.profile script and mount it at that time. This would allow the mounting to be done transparently, and only mount it for that user. I think that is what 'a thing' has in mind.


All times are GMT -5. The time now is 03:38 PM.