3

Each user should be able to access a cifs group share using his own credentials when navigation to a specific folder ~/groupdrive inside his home folder. The credentials are stored in a ~/.cifs_credentials file.

I implemented this using pam_mount but I'm stuck with tons of duplicate and not properly unmounted mounts.

How can I implement this behaviour using autofs? Is it possible to mount share multiple times on the same mountpoint eg /mnt/groupdrive with different credentials and symlinking to it from the home folder?

Fab
  • 31

1 Answers1

2

You can use variables in autofs which may be a solution to your requirement. Everybody has their own way of doing autofs and this is mine. I just did this on Ubuntu 18.04 primarily to see if it still works at this release:

I edited /etc/auto.master and as the last line added:

/mnt/Samba /etc/auto.sambashares --timeout=30 --ghost

I purposely made the parent folder /mnt/Samba and not something under /media or the home directory because it results in mass confusion by the OS.

I edited /etc/auto.sambashares and added one line using the ${HOME} and in my case the ${UID} variables:

GroupShare -fstype=cifs,rw,credentials=${HOME}/.cifs_credentials,uid=${UID},iocharset=utf8 ://server/share

Then restarted the autofs service.

When usera accesses /mnt/Samba/GroupShare ( which can be bookmarked ) his credentials at /home/usera/.cifs_credentials will be used to access the share and userb will use his own credentials in his own home directory.

Alternate Method for Concurrent Users:

** Create a parent folder under /mnt for each user - example: /mnt/bob and /mnt/mary.

** Change ownership to each user ( i.e., sudo chown bob /mnt/bob )

** Limit access only to that user ( sudo chmod 0770 /mnt/bob )

** Replace the one line in auto.master to two:

/mnt/bob/Samba /etc/auto.sambashares-bob --timeout=30 --ghost
/mnt/mary/Samba /etc/auto.sambashares-mary --timeout=30 --ghost

** Then create the two auto.sambashares-xxx files each having the same line:

GroupShare -fstype=cifs,rw,credentials=${HOME}/.cifs_credentials,uid=${UID},iocharset=utf8 ://server/share
Morbius1
  • 8,437