Mount at boot a samba share and make it writeable for a non-root user


Lately I was busy trying to map a network HDD with samba. The device in question an O2media HMR-2000. I can browse its contents via Dolphin with smb:// protocol, but I was unable to delete files with other user than root. Also, I was unable to “map” the shared folder into my home because a parenthesis on the shared resource.

First of all, I tried to change the share name and remove those annoying parenthesis. But I simply couldn’t. The share name is harcoded on the smb.conf on the HMR-2000 and each time I reboot the device, the share name backs to HDD(SATA) >.<

Well, then I modified /etc/fstab to mount the device at boot time. That is not recommendable, because if the device is offline when my pc boots, the boot time will be delayed a lot, until samba timeout occurs. But I have no better idea how to accomplish that… any advice is welcome.

So, before modify our fstab, let’s see some useful information we’ll need in order to make it work. If you are, like me, the only user of the PC, you will need to know your user id and group id to gave to you the permissions. So:
$ id malevolent
uid=1000(malevolent) gid=100(users) grupos=100(users),10(wheel),50(games),91(video),92(audio),93(optical),95(storage),98(power),140(usbmux),108(vboxusers)

I am uid=1000 and my gid is 100. I belong, amongst others, to group “users”. So now will edit /etc/fstab and let’s add the following line to the end of the file:
// /home/malevolent/Network cifs auto,credentials=/home/malevolent/.o2media_credentials,rw,user,users,auto,exec,uid=1000,gid=100 0 0

Where is the network HDD ip address, and HDD1(SATA) is the share name. Note that fstab recognices those parenthesis without the need of quote the whole UNC path as bash prompt needs to.
/home/malevolent/Network is the mountpoint where I want to map the shared folder.
cifs the filesystem type-
credentials=/home/malevolent/.o2media_credentials,rw,user,users,auto,exec,uid=1000,gid=100 are the parameters: credentials will point to a file with our username and password for that shared resource, see below to have an example of this file. rw will tell that the folder will be writeable for the user and groups with the specified uid and gid.

To strengthen security, you should never put your credentials visibles on fstab. So create a file with the credentials and point to it in fstab with the paramether credentials. The file in question must be like this:

Where USERNAME and PASSWORD must be the user name and the password to access that shared resource. A useful trick to those shared resources available to Guest users, is to left blank USERNAME and PASSWORD like the following example

Hence, at boot time, it will not wait until you press Enter button. 😉

So reboot or sudo mount -a to see how it mounts on the mountpoint and you have full rights on your new mapped folder.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s