Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm working with over SSH with an external hard drive connected by USB.

I know I can manually mount a drive with the following command:

sudo mount /dev/sdc ~/dirToMountTo

The problem is, if I don't do it as root, then it says "mount:only root can do that".

If I do it as root, though, I can't access, read, or write files as a regular user. Only root has permissions to do anything in the directory.

How do I mount it so that I can work within it without being root?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

If you do this often, you may add a line to your /etc/fstab which will tell that the partition can be mounted by a non-root user. Something like this:

/dev/fd0        /media/floppy0  auto    rw,user,noauto,exec,utf8 0       0

here, the 'user' option does what you need. See 'The non-superuser mounts' in mount's manfile.

The 'noauto' option tells the boot scripts not to attempt to mount the filesystem on boot (see the documentation for -a switch for mount command). Instead, you will be able to mount it explicitly by issuing

mount /dev/fd0

or

mount /media/floppy0

Also, the user who mounted the filesystem should be able to unmount it too.

For a one-off mount you need to specify uid=value or gid=value to make all the files on the mounted filesystem to be owned by that user. See "Mount options for fat" in mount's manfile.

share|improve this answer
    
Thanks for your answer. I need to do this mount command only when the USB drive is plugged in, though. If I add the line to fstab as you suggest, then won't it only apply when the computer boots? And then how would I unmount the drive when I'm done with it? –  Questioner Aug 10 '11 at 6:17
    
@Sergey: on ext4 fs, the permissions on the files of the filesystem are independent on who mount the partition, i think. –  enzotib Aug 10 '11 at 6:32
    
@enzotib - you're right, I presumed the external USB-mounted drive has FAT or NTFS filesystem (which they have OOTB unless the drive was re-paritioned) –  Sergey Aug 10 '11 at 7:02
    
@Dave - I added some details on the 'noauto' option to the question –  Sergey Aug 10 '11 at 7:10
    
Awesome! Seems to be working. My only remaining question is... will the drives always be mounted at the same place - in other words, /dev/sdc, and not, say one time be mounted at /dev/sdd or /dev/sde or something? –  Questioner Aug 10 '11 at 8:04

It depends on the type of filesystem.

For FAT32 or NTFS you need to specify mount option to give your user read right.

For ext3 or ext4 you have to change permissions on the filesystem itself.

share|improve this answer
    
I believe it is FAT32 or similar. It's the internal USB accessible hard disk inside an Android smartphone, and the formatting was done at the factory. I looked at it with gParted one time, and it came up as FAT (I would prefer to work in ext3 or ext4, but I don't really want to get involved in formatting the phone's HD). –  Questioner Aug 10 '11 at 6:35
    
@Dave M G: so add to your mount command the option -o uid=$USER,gid=$USER. You could also need to set umask=0022 –  enzotib Aug 10 '11 at 6:40
    
Thanks! I will try that later when I'm at my home computer and hopefully report back some success. –  Questioner Aug 10 '11 at 6:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.