Does anyone know how to automatically mount a CIFS share at login (not boot) for a user using specifically their credentials?
If multiple users are to login, then simply mount the share multiple times for each user (in a different read/write protected directory) using each users credentials.
I've been looking into trying to get a network CIFS share to mount on user login (and unmount at user logout). Though I can easily mount the network share at boot, and using a systemd service, I'm struggling to adapt this to mount for a user on login.
Since the network share has tailored permissions for each user, it only makes sense to mount the share for each user. I was thinking that using a systemd user service would be good, but it doesn't want to work.
Below is the systemd user service I've been trying to use (which doesn't work).
# /home/robertfry/.config/systemd/user/media-freenas.saturn.local-Media.mount [Unit] Description=Mount FreeNAS Saturn Media (freenas.saturn.local) [Mount] What=//freenas.saturn.local/Media Where=/media/freenas.saturn.local/Media Type=cifs Options=credentials=/home/robertfry/.config/freenas.saturn.credentials,iocharset=utf8,rw
Note: I have
freenas.saturn.local defined in my /etc/hosts file
Though this service works perfectly as a systemd service (at /etc/systemd/system/), it fails when I try to start it as a user service.
After a little searching, I've read that there should be an entry in /etc/fstab for mounting to work. However, this blocks the systemd service from running, and I'm not able to change which credentials are used for each user.
//freenas.saturn.local/Media /media/freenas.saturn.local/Media cifs _netdev,noauto,x-systemd.automount 0 0
The entire gist of what I want is to mount the share at login using a users credentials at login.