Mounting a shared folder in everyone's home directory

Simón Ruiz simon.a.ruiz at gmail.com
Thu Apr 29 21:38:40 BST 2010


On Thu, Apr 29, 2010 at 9:44 AM, David Groos <djgroos at gmail.com> wrote:
> Got it!  Thanks for your help, Simon.  Here were the steps, feel free to
> edit/improve/annotate them as useful--I'll be making a simple wiki page on
> this.
>
> 1.  sudo apt-get install smbfs
> 2.  Make folder on my desktop, named it, "dogimages" (not sure if must be
> lower case)
> 3.  Right-clicked and selected Sharing Options, selected, Share this folder
> and Guest access. (little flag appears on folder--I'm using Jaunty).
> 4.  Make the mount point-- sudo mkdir /media/dogimages (Directory name must
> be all lowercase, it seems)

The case shouldn't matter as far preventing a name choice, so long as
you consistently refer to it by the same name.

Linux file-systems are case-sensitive so "/media/Dogs" is a different
directory than, and can exist next to, "/media/dogs" and
"/media/dogS".

Here, I've got /home/username/Desktop/Dogs shared via samba as the
share name "Dogs", and mounted on /media/Dogs

> 5.  sudo mount -t cifs -o guest //localhost/dogimages /media/dogimages
> 6  And a sharepoint mounted on my desktop! (is it called, 'sharepoint'?  I
> was looking for a word to distinguish it from the folder created in step 2)

A shortcut? A link? An icon? There's probably a particularly good word
for it, but I can't think of it myself.

> 7. I added an image to the shared folder that I had created in step 2 and
> the image appeared in the mounted sharepoint :)

Also, you might want to verify that you can't delete the photo through
the mounted share, just to double-check your permissions.

> This is great.  Thanks for the detailed info.

Glad to be of help.

> My next step (I'm not in a rush to do this) is that I will want to be able
> to fine tune on whose desktop this shows up.  I want to be able to manage
> this by group membership.  In other words I've got a group on my server
> called, "period2".  I want to similarly mount a shared folder on the desktop
> of just members of that group.  Is it very complex task?

Heheh, now you're moving up the ladder.

It's slightly more complex up front to set up, but it ends up being
easier to maintain.

You could set up pam_mount, which is designed to integrate into the
system's logon process and take care of mounting things on login (and
unmounting them on logout) based on any number of conditions (hey,
sounds like what you wanna do). ;-)

First you gotta install the package "libpam-mount", then you gotta
edit it into your /etc/pam.d config files to exhibit the desired
behavior...

A copy of the official documentation for doing that is at
<http://manpages.ubuntu.com/manpages/karmic/man8/pam_mount.8.html>,
but I don't know how easy that will be to follow.

You can see my notes on how I integrated pam_mount into our config
files under Hardy Heron over at
<http://tech.canterburyschool.org/tech/UbuntuWorkstations/AuthenticationSetup>;
we were also integrating winbind authentication, too, and those config
files are a little old so I don't suggest trying to copy what we did
verbatim, but they might serve as illustrative in that I inserted one
line into common-auth and one into common-session.

Once you have it integrated into the login process, you simply edit
the /etc/security/pam_mount.conf.xml to add the shares you want
auto-mounted.

In our documentation above, I only added the user's home folder being
mounted over Samba, but pam_mount is able to be set up to mount all
kinds of stuff, including local bind mounts (removing the need for
running a Samba share if all you care about is sharing things on the
local drive), and conditional mounting (so you can specify different
mounts for different users).

Say you get pam_mount installed and running, then you edit the
pam_mount.conf.xml script with a volume tag such as...

<volume path="/home/teacher/Desktop/Dogs" mountpoint="~/Desktop/Dogs"
options="bind" />

Now anyone who logs in will automatically have the
/home/teacher/Desktop/Dogs folder "bound" ("binded"?) to their own
~/Desktop/Dogs folder.

Then you decide only "period2" should have that mounted? No problem,
just add one option to that line and turn it into:

<volume path="/home/teacher/Desktop/Dogs" mountpoint="~/Desktop/Dogs"
options="bind" sgrp="period2" />

Now it checks to see if the user is in the group "period2", and mounts
this volume only if they are.

Period 3 is studying cats, you say? Just add:

<volume path="/home/teacher/Desktop/Cats" mountpoint="~/Desktop/Cats"
options="bind" sgrp="period3" />

At this point, you're not even pretending to use the network anymore
so the Samba server or smbfs mounting packages are not involved, and
don't need to be installed.

You will need to make sure that the shared folders have sane file
permissions (which they should by default, but you could run "chmod -R
755 /home/Desktop/Cats" to be sure); as readable to all, but not
writable by anyone but the owner).

You can check out a copy of the pam_mount.conf manual over at
<http://manpages.ubuntu.com/manpages/karmic/man5/pam_mount.conf.5.html>
to see all the other shiny knobs and levers it has.

Hope this helps,

> David

Simón



More information about the ubuntu-education mailing list