How to automatically mount a CIFS share upon user login in RStudio Server (Open Source)?

Hi everyone,

(To be clear, sorry but AI is used to solve the issue and to write this post)

I am looking for a reliable way to automatically mount a unique Windows CIFS share (//<IP>/directory) into each user's home directory (/home/username@domain.org/directory) when they log into the RStudio Server Open Source web interface.

The mount must use the user's native Active Directory (AD) Windows permissions.

Our Environment:

  • OS: Ubuntu (integrated into an Active Directory domain using SSSD).
  • Application: RStudio Server (Open Source version).
  • Users: AD users (e.g., username@domain.org / short name: username).

What already works perfectly:

  1. SSH Login: Standard AD authentication works seamlessly. The home directory is automatically created upon first login.
  2. Manual CIFS Mount: Running this command as root/sudo works perfectly:
    sudo mount -t cifs //<ip>/directory /home/username@domain.org/directory -o username=username,domain=domain.org,uid=username@domain.org,gid=12345,file_mode=0700,dir_mode=0700

What we tried (and why it failed on the Open Source version):

  1. PAM (pam_mount.so): Works flawlessly for SSH, but fails for RStudio Server. During the session phase, RStudio Server Open Source drops root privileges and switches to the unprivileged user before executing system mounts. Also, RStudio does not seem to pass the clear-text password down the PAM stack in a way pam_mount can reuse.
  2. session-prologue-script (rserver.conf): Fails with an unrecognised option error because this directive is exclusive to RStudio Workbench / Pro.
  3. Global R Profile (Rprofile.site) + Sudoers script: We triggered a Bash mounting script via Rprofile.site using a NOPASSWD sudoers rule. System logs show the script executes successfully as root. However, the mounted folder remains invisible or inaccessible inside the RStudio user session UI. We suspect this is due to how RStudio Open Source isolates the user session namespace before R initializes.

My Question:

Since session-prologue-script is not available in the Open Source edition, what is the best practice to trigger a per-user CIFS mount at the exact moment the web session initializes, so that the mount is correctly propagated into the user's R session namespace?

Should we look into dynamic autofs triggers, an rsession binary wrapper script, or is there an alternative hook within RStudio Server Open Source that we missed?

Thank you for your help!

You need to create automounts for each users.

I wil give you an example of a user named 'myuser' which has a typical homedirectory '/home/myuser'. The cifsmount needs to be mounted inside the users homedirectory eg. '/home/myuser/projects' or something.

Lets say your samba share is '\myserver\rstudio\projects' and myuser (or any user) must access it

Create two files in /etc/systemd/system (both chmod 644):

  • 'home-myuser-projects.mount'
  • 'home-myuser-projects.automount'

Create a credentials file '/root/.rstudio-projects.cred' containing (eg.) The supplied credentials are for the samba share.

user=<username of the sambashare>
password=<password of above user>
domain=

Content of home-myuser-projects.automount:

[Unit]
Description=rstudio\projects on myserver

[Automount]
Where=/home/myuser/rstudio-projects
TimeoutIdleSec=360

[Install]
WantedBy=multi-user.target

Content of home-myuser-projects.mount:

[Unit]
Description=rstudio\projects on myserver
Requires=network-online.target
After=network-online.service

[Mount]
What=//myserver/rstudio/projects
Where=/home/myuser/rstudio-projects
# gid and uid should be able to handle named user and group otherwise get real uid  and gid eg 1001 and 1001
Options=vers=3.0,credentials=/root/.rstudio-projects.cred,uid=myuser,gid=myuser,rw,serverino,file_mode=0660,dir_mode=0775
Type=cifs

[Install]
WantedBy=multi-user.target

Execute systemctl daemon-reload
Execute systemctl enable --now home-myuser-projects.automount

Then when 'myuser' logs and access '/home/myuser/projects' the share is automagically mounted. I can't remember if you need the create the mountpoint. With normal .mount files it's created on startup.

You can use the two mount* file for every user if needed.. If you df -hP you will then see that '\myserver\rstudio\projects' is mounted on multiple mountpoints - which is fine. Don't forget to change the Where= and at Options= the gid and uid. Those needs to reflect the user.

Regards
S.

Great hints! It really helped me to setup my share in the r-server. Thank you!