HOWTO allow users mount external devices
Posted by notKlaatu , 04 March 2008 · 218 views
For quite a while, I was fine with my Slackware system not allowing normal users to mount external drives or optical discs -- because I very rarely used external drives or discs under Slackware. Lately I purchased a small portable drive that I am using to organize and keep my personal data, so I've been moving a lot of stuff from DVD-Rs to this drive, and it started to become bothersome to "sudo mount" everything and then "sudo umount" and enter the passwords and the device locations and mount points. So I decided to figure out how to allow my normal user identity to mount these external devices. This is very poorly documented in the books I have on the subject, so here's how: ''Please note that the # indicates things done as root, and % denote regular user.'' 1. As root, open in a text editor the /etc/fstab file. I use vim, but you can use pico or nano or whatever you like.
# vim /etc/fstab2. There are already entries here by default, and they look a little something like this:
/dev/sda1 / ext3 defaults 1 1 /dev/hda /media/cdrom iso9660 user,ro 0 0(and so on...) the idea here is that the first column is the device location and the second is the mount point. The third is what kind of filesystem it will default to. The fourth is who gets to mount it. And the fifth and sixth are related to fsck (file system check). Many of the entries in /etc/fstab by default are the mount points of your actual operating system. So there's the root mount point, there's the mount point for proc and maybe a floppy drive (or SD card reader, in the case of my Vaio). You probably won't necessarily need to mess with the root and proc mount points; instead, you'll be either adding or editing the entries for the optical drive, SD card reader, and external hard drive. So if you know your optical drive is located at /dev/hda and you know you want to put it in the /media/cdrom folder when it's mounted, the entry would begin as such:
/dev/hda /media/cdromOptical discs are pretty much always the filesystem type of iso9660 so that's the third column. The fourth column - the users who get to mount it - is the tricky one. If you want only ROOT to be able to mount that device, then put the word "root" in the fourth column. If you want any USER to be able to mount that device, then put the word "users" (not the username; the actual word "user"!) in the fourth column. And just to be clear about this, the presence of ROOT in the fourth column will make it so that ONLY root will be able to mount it. So if you want a user to be able to mount it, ONLY "users" should be placed in the fourth column, not "users,root". We must assume that if a user can mount a drive, so can root.... but if root can mount it, then only root can mount it. Makes sense if you think about it. If the device is read-only, add the word "ro" in the fourth column. If it's readable and writable then add "rw". The last column you can leave as is. So in the end, my /etc/fstab had this added to its default list:
/dev/hda /media/cdrom iso9660 user,ro 0 0 /dev/sdb1 /media/hd auto noauto,user,rw 0 0This allows the user to mount a cd or dvd as read-only at the mount point /media/cdrom as well as a hard drive plugged into the USB port (regardless of filesystem type, which will simply be auto-detected) as a read-write device at the mount point /media/hd As user, type in simply
% mount /media/hdand it will be mounted for you. No need to type in % mount /dev/sdb1 /media/hd or anything complex like that. If you do this, you will be prompted for more information because it is assumed that you are attempting to override fstab.Why not use /mnt instead? Simply because, since I sometimes use Konqueror, it's easier to mount things by default to the /media folder, as Konquerer by default checks /media for mounted filesystems. No reboot required, no logout required! It just works right away! That's it!Actually that's not quite it. There MAY be a permissions issue, depending on your distro. If, for instance, you are defining the mount point as /media/hd and the USER has no permission to write to /media/hd then the USER won't be able to copy files on the hard drive. So as root, you'll need to change permissions of the /media/hd directory to something that includes write permission for the everyday user. Like so:
# chmod -hR <USERNAME> /media/hdNow mount the drive to that directory and watch in amazement as the everyday user is able to read and write to the drive!That's it.