Site icon The Ultimate Linux Newbie Guide

How to mount a USB stick as a non-root user with write permission

So you want to use a USB stick or a USB hard drive, and you don’t want to mount it as root every time?

Why would you want to do this?

Another point worthy of note, if you are someone who uses a shiny, full fat desktop like GNOME or KDE, then you’ll likely find that things like USB removable media are automatically mounted for you, so it is often fine to use it in that capacity. However, for Linux luddites and server admins like me, that just won’t cut it, I want an easy user-level mount at the command line, or bust!

Ok, you’ve made up your mind that you want to be able to mount the disk as a real user, not root. The good thing is, is that this is really quick to do.

Firstly, we need to create a directory where the drive is going to be mounted to. So if you haven’t done so already, create this directory:

$sudo mkdir -p /media/<username>/usb
$sudo chown <username> /media/<username>/usb
$sudo chmod 0777 /media/<username>/usb

Obviously, you can call the mount point whatever you want, I’ve just called it usb and stuck it in the /media/<username>/usb directory (note <username> is your own username). The last two commands change the ownership to be ‘you’, and sets the permissions to read and write for all users (change this if you want it to be less open).

Next up, we need to ascertain which drive you want to mount. You may already know this, but if you don’t know what the /dev/ entry for the USB stick is, then you can find this out by sticking it in the usb port on your machine and running dmesg:

$dmesg
[snip]
[95921.903363] usb-storage 1-2.2:1.0: USB Mass Storage device detected
[95921.903445] scsi host5: usb-storage 1-2.2:1.0
[95922.902013] scsi 5:0:0:0: Direct-Access USB DISK 2.0 PMAP PQ: 0 ANSI: 6
[95922.902347] sd 5:0:0:0: Attached scsi generic sg2 type 0
[95923.714434] sd 5:0:0:0: [sdc] 15133248 512-byte logical blocks: (7.74 GB/7.21 GiB)
[95923.714639] sd 5:0:0:0: [sdc] Write Protect is off
[95923.714642] sd 5:0:0:0: [sdc] Mode Sense: 23 00 00 00
[95923.714848] sd 5:0:0:0: [sdc] No Caching mode page found
[95923.714851] sd 5:0:0:0: [sdc] Assuming drive cache: write through
[95923.719842] sdc: sdc1
[95923.721331] sd 5:0:0:0: [sdc] Attached SCSI removable disk
[/snip]

You can see that it’s detected that a USB storage device on sdc, and that the partition it can see is called sdc1 (highlighted above in bold).

Now all you need to do is edit the /etc/fstab file and add this line at the bottom:

$sudo vim /etc/fstab

/dev/sdc1 /media/usb auto user,umask=000,utf8,noauto 0 0

Remove the ‘noauto’ bit if you want it to be mounted automatically on boot, however that’s probably a bad idea if its a removable device!

That’s all the hard work done, and you shouldn’t have to do that ever again, now all you need to do to mount it, whenever you like, is to issue a simple mount command:

$mount /dev/sdc1

or, alternatively you can mount it by its mount point. Either way, it doesn’t matter 🙂

$mount /media/<username>/usb

Hope this saves you some aggravation!

Exit mobile version