LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   enable users to mount external usb hard drives w/o changing fstab (http://www.linuxquestions.org/questions/linux-general-1/enable-users-to-mount-external-usb-hard-drives-w-o-changing-fstab-864763/)

someshpr 02-24-2011 08:41 AM

enable users to mount external usb hard drives w/o changing fstab
 
Hi,
I always have trouble with this one!
In our office we have some machines running CentOS 5, some running CentOS 4, and one running WinXP! We have external usb hard drives some are formatted ext2, some ext3, some fat32, and some NTFS. I tried to tweak with the fstab so that hard drives will be mounted automatically. But given the different file systems and OSs, I couldn't find a common and generic way to do it, unless I put all possible usb drives and their mount commands in the fstab file. I tried to do it using mount by labels, but realized that there are hard drives with same label but different file systems. So in a nitshell, its complicated!

Till now I have been manually mounting by changing the fstab as root for a particular machine whenever any user needs to connect their hard drives.

But I was wondering if there is a way to give all the users the permission to use the 'mount' and 'umount' command without tweaking the fstab file?

TIA,

bigrigdriver 02-24-2011 06:14 PM

Quote:

Till now I have been manually mounting by changing the fstab as root for a particular machine whenever any user needs to connect their hard drives.
Editing fstab shouldn't be necessary to mount the drives. When you plug the drive in, it's assigned a to a device file in /dev, for example: /dev/sdc. Then you mount it: mount -t ext2 /dev/sdc /mnt (the mount command, followed by the filesystem type, the drive device, and the mount point). Fstab is not involved.

Quote:

But I was wondering if there is a way to give all the users the permission to use the 'mount' and 'umount' command without tweaking the fstab file?
To give users permission to mount/umount drives, investigate setting up /etc/sudoers to give individual users permission to mount/umount. Note that to edit the sudoers config file, you must use the visudo editor: visudo /etc/sudoers (run as root).

jefro 02-24-2011 09:04 PM

Isn't there some user permission setting for removable media or something like that? Just enable it and users simply plug in and it gets automounted. Pretty sure it is in the gui but ought to be able to access in command line maybe. Dunno, just thinking.

EDDY1 02-24-2011 10:30 PM

Quote:

Isn't there some user permission setting for removable media or something like that? Just enable it and users simply plug in and it gets automounted. Pretty sure it is in the gui but ought to be able to access in command line maybe. Dunno, just thinking.
Would it be plugdev in users and groups?

someshpr 02-24-2011 11:16 PM

Quote:

Originally Posted by bigrigdriver (Post 4270266)
Editing fstab shouldn't be necessary to mount the drives. When you plug the drive in, it's assigned a to a device file in /dev, for example: /dev/sdc. Then you mount it: mount -t ext2 /dev/sdc /mnt (the mount command, followed by the filesystem type, the drive device, and the mount point). Fstab is not involved.


To give users permission to mount/umount drives, investigate setting up /etc/sudoers to give individual users permission to mount/umount. Note that to edit the sudoers config file, you must use the visudo editor: visudo /etc/sudoers (run as root).

These machines have multiple users none of whom have or should have root/superuser privileges. If I do not change fstab, only I can mount as root using the "mount" command. It doesn't really help the user as user has access and permission problems when the external drive is mounted as root. But if I change the fstab, add a line with proper mount parameters giving user rw permission, and do a "mount -a" as root, then user can mount it by himself without any permission problem.

Playing with sudoers seems a good idea. I'll work on that.

Quote:

Originally Posted by jefro (Post 4270393)
Isn't there some user permission setting for removable media or something like that? Just enable it and users simply plug in and it gets automounted. Pretty sure it is in the gui but ought to be able to access in command line maybe. Dunno, just thinking.

I have no idea where this user permission settings are for removable media. Also I need a command not a gui tool, I do not have a desktop environment in all the machines!

bigrigdriver 02-25-2011 12:50 AM

Another approach to consider is to setup udev rules to automount the usb drives with appropriate mount options. There would be a set of rules for each filesystem type that might be plugged in.

The Arch Linux wiki has a good example of the type of rule sets you would need.
https://wiki.archlinux.org/index.php...ng_USB_devices

LlNUX 02-25-2011 01:06 AM

Hi, have you considered to install and configure autofs?

someshpr 03-15-2011 11:26 AM

Changed sudoers files and seems to work as I wanted. Added these two lines:
Code:

Cmnd_Alias MOUNT = /sbin/fdisk, /sbin/sfdisk, /bin/mount, /bin/umount

%access.workstations ALL=NOPASSWD:MOUNT

access.workstations is the group all users belong to.

And since this seems to work didn't try with autofs. Also setting up udev posed difficulty for older machines (CentOS 3) and didn't dig deeper on that line.

Thanks,


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