SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2012-05-04 21:49:38

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

how to: get non-root write-access to stuff on your external drive(s)

the only way i could write stuff to my FAT32/VFAT-formatted USB-stick was as root (using sudo, in this case).
the only way i could write stuff to my ext4-partitions was as root.
i could, however, write stuff as a regular user to my ntfs-partitions, mounted with ntfs-3g.

this whole situation would not stand. it is annoying, and i was tired of using my workarounds for easy filemanagement on these drives (using 'sudo mc'). so i decided to figure out how to get what i wanted: write-access on my external drives as a regular user.

THE BASICS
the rules for mounting stuff are set out in the /etc/fstab file. if you want to edit it, you must do so as root, so use

gksudo gedit /etc/fstab

to open it (assuming gedit is your editor here). we'll be referring to this file as simply 'fstab' from here on out.
for more info on the fstab-file, please read over here: https://wiki.archlinux.org/index.php/Fstab

to find out your drive's UUID, use the command 'blkid -o list'.

FAT32/VFAT
the FAT32 filesystem has no real ownership-stuff. so, in order to fix that, you have to add a bunch of mount-options. the following line should work:

#Entry for Moskeyto:
UUID="FC30-3DA9"    /media/SD       vfat    user,rw,auto,nofail,umask=111,dmask=000,flush     0 0

i got that info from over here: https://wiki.archlinux.org/index.php/Fs … ormal_User

NTFS
for NTFS-drives, use ntfs-3g to mount it. it seems that already allows you to write to it as a regular user.

UUID=0E44E20A44E1F47D    /media/Xochipilli    ntfs-3g uid=rhowaldt,fmask=113,dmask=002,user,rw,auto,nofail,exec,locale=en_US.UTF-8    0    0

EXT4 (and others, i suppose...)
i didn't really find a good solution for this one like the one for FAT32, so i embarked on my own adventure. i figured the problem had to be with who the owner of a drive is. the question is, however: how do you change the owner of an external drive? it turns out you can just mount it, then use the 'chown' command on the mountpoint, which will in turn change the owner of the drive. (when there is no device mounted on the mountpoint/directory, the owner is still root. as soon as you mount a drive, the owner of the mountpoint/directory changes to reflect the ownership of the drive). great. so what i did was:

sudo mount /media/void
sudo chown rhowaldt /media/void

(replace 'rhowaldt' with your own username, of course)
in effect, my fstab-entry for ext4 looks nothing special, but here it is:

#Entry for void :
UUID=2104150d-2819-4a96-b8d8-d83053551f45   /media/void         ext4    user,rw,auto,nofail,noatime  0   0

THE END (?)
now, let me just mention here that i have no idea whether doing stuff this way raises any security-issues. i like to think it doesn't, but i just don't know. however, if you are uncomfortable with doing this, let me give you another method you could use.
assume the drive we're using is mounted on /media/SD. do the following.

cd /media/SD
sudo mkdir bla
sudo chown rhowaldt bla

(again, replace 'rhowaldt' with your own username, of course)
after doing this, you'll find you cannot create a new directory inside /media/SD as a regular user. you can, however, create a new directory inside /media/SD/bla as a regular user, because you own that directory. this way, you could have root-owned and user-owned directories on the same drive.
less security-issues? dunno. you tell me big_smile

hope that helps somebody. if there are any glaring inaccuracies or whatever, please let me know and i'll correct them. also let me know if this is working for you or whatever.

edit: with the blessing of el koraco, you might also want to consider using pmount instead. it does all the work for you.

Offline

Help fund CrunchBang, donate to the project!

#2 2012-05-04 22:08:36

2ManyDogs
dv#!
From: elsewhere
Registered: 2011-11-22
Posts: 1,346

Re: how to: get non-root write-access to stuff on your external drive(s)

Thanks rw. Good how-to. I got tired of automounting breaking every other day, so I added an entry to fstab for my backup USB stick (it's always connected, so this works for me):

# 8Gusb is sdb1 during boot
/dev/sdb1   /media/8Gusb        ext4    defaults,nofail   0   0

then I have mount points in /media for my 2G usb stick and 320G backup drive that I chown'd like your how-to. I don't use thunar and I removed gvfs. Funny how much less complicated it can be... hmm

Last edited by 2ManyDogs (2012-05-04 23:22:55)


Be eggsalad to each other.

Offline

#3 2012-05-04 22:12:16

machinebacon
#! unstable
From: PRC
Registered: 2009-07-02
Posts: 6,212
Website

Re: how to: get non-root write-access to stuff on your external drive(s)

Finally somebody wrote it, thanks a lot rhowaldt!


Start Distrohopping here! -> Break your own... cool  VSIDO  cool LinuxCNC  kiss Frugalware <- It's all just a kernel.

Offline

#4 2012-05-04 22:44:16

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: how to: get non-root write-access to stuff on your external drive(s)

thanks guys!

as you can see, there is also a lot of other fstab-related stuff in there which i didn't really explain. like using UUIDs to reference your drives, and stuff like the 'flush' parameter on the FAT32 partition, or the 'auto,nofail' combo to stop errors when the device is not connected during boot.
since this is not an fstab-tutorial, i didn't really go into that. hopefully people will read the link i provided and figure all that out themselves.

also, i'm not 100% sure about ntfs-3g allowing non-root write-access by itself. all i know is it works for those drives that use it, but i also have all these fstab-options there, and it is possible that they are what causes this to work for my NTFS-drives instead of ntfs-3g... if anyone knows this for sure, let me know because i may have to correct my post.

Offline

#5 2012-05-04 22:55:05

el_koraco
#!/loony/bun
From: inside Ed
Registered: 2011-07-25
Posts: 4,644

Re: how to: get non-root write-access to stuff on your external drive(s)

Oh man, you really want the hard way. You could have installed pmount, it lets you mount and unmount as regular user big_smile

Offline

#6 2012-05-04 22:57:59

2ManyDogs
dv#!
From: elsewhere
Registered: 2011-11-22
Posts: 1,346

Re: how to: get non-root write-access to stuff on your external drive(s)

pmount is bloat smile


Be eggsalad to each other.

Offline

#7 2012-05-04 23:09:31

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: how to: get non-root write-access to stuff on your external drive(s)

@el_koraco: from my experience, mounting/unmounting as regular user doesn't have any effect on whether you also get write-access as a regular user. does pmount handle that as well?
btw, even if it does, what i really wanted to do was figure out how this stuff works, instead of using an app that does it for me. knowledge is power smile

Offline

#8 2012-05-04 23:12:11

machinebacon
#! unstable
From: PRC
Registered: 2009-07-02
Posts: 6,212
Website

Re: how to: get non-root write-access to stuff on your external drive(s)

2ManyDogs wrote:

pmount is bloat smile

lol Thanks for that!


Start Distrohopping here! -> Break your own... cool  VSIDO  cool LinuxCNC  kiss Frugalware <- It's all just a kernel.

Offline

#9 2012-05-04 23:31:45

el_koraco
#!/loony/bun
From: inside Ed
Registered: 2011-07-25
Posts: 4,644

Re: how to: get non-root write-access to stuff on your external drive(s)

rhowaldt wrote:

@el_koraco: from my experience, mounting/unmounting as regular user doesn't have any effect on whether you also get write-access as a regular user. does pmount handle that as well?

It does.

Offline

#10 2012-05-05 01:36:30

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: how to: get non-root write-access to stuff on your external drive(s)

^ good to know. sounds like a proper app then, handling this stuff. however, as i said, i really had to figure out how this worked once and for all. using pmount instead is a good suggestion, but it would've cost me the feeling of accomplishment i have now smile

edit: added a note about pmount to my first post. thanks for the suggestion Mr Koraco.

Offline

#11 2012-05-05 03:22:51

johnraff
#!Drunkard
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 2,466
Website

Re: how to: get non-root write-access to stuff on your external drive(s)

I learnt about fstab here:
http://ubuntuforums.org/showthread.php?&t=283131
Old Ubuntu forums post by bodhi.zazen - you needn't don't bother with that pysdm thing, but the basic stuff is there, clearly described.

But...

the only way i could write stuff to my FAT32/VFAT-formatted USB-stick was as root (using sudo, in this case).

...why? What OS are you using? On standard #! I just plug in a usb stick (ext2 or vfat) and voila!

Some while ago I was running a dual boot Win98/Linux and had the windows fat32 partition in the Linux fstab so it mounted with my user permissions, and with Japanese filenames displaying OK. Took much googling to get that fstab line fixed, and indeed, a feeling of accomplishment. smile

/dev/sda1    /win    vfat    auto,rw,uid=1000,gid=1000,umask=022,shortname=mixed,codepage=932,utf8    0    0

However, if the system can do it for me, and doesn't mess up, I'm happy to let it do its thing. There are only 24 hours in a day, and we each have to allocate them as we see fit I guess.


John
--------------------
( a boring Japan blog , and idle twitterings )

Offline

#12 2012-05-05 06:04:31

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 9,017

Re: how to: get non-root write-access to stuff on your external drive(s)

Only time I've had trouble writing to external hard drives was if there *was* a line for /dev/sdb1 in fstab; fix for me was to just delete the line and be on my merry way.  All my USB drives are FAT32 (flash) or NTFS (hard drive), however.


while ( ! ( succeed = try() ) );
We've earned a reputation as a nice, friendly community; please help us keep it that way.

Offline

#13 2012-05-05 12:06:43

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: how to: get non-root write-access to stuff on your external drive(s)

@johnraff: i'm still running the Feb '11 #! release, but modified by myself over time. seems to me my USB-sticks might have automounted from the start, but i ditched Thunar and it's automounts some time ago in favor of doing more of my work through the terminal. so that means making it harder on yourself and having to set things up manually.

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo