I use the systemd-mount method (which automatically mounts / unmounts the share, seamlessly.)
I can share a template of what I use, and then let you change it for yourself and explore it further.
First you need to create two systemd units: one for the actual mount, and the other for the automount trigger.
Secondly, if you don’t want the password to be used in the systemd mount unit itself, you can create a hidden / restricted-access file that contains the credentials.
It’s easier to manage if you create a hidden directory named “.cifs” in your home folder, in which only your user has access to it. From here, you can create templates and use them to copy over the the actual system folder.
Replace all instances of “sharename” with the actual share’s name configured in your SMB server. (Do the same for mentions of “winnie” or the home folder location.)
Inside this folder, create a file named
.cifs-sharename-credentials with the contents that look like so:
Restrict it for only your user:
chmod 600 ~/.cifs/.cifs-sharename-credentials
Also in this folder, create two files. The names must follow this format. They instruct systemd where the mount paths exist. (Example: “mnt-cifs-sharename” tells it that the mount location will be
mnt-cifs-sharename.mount with the contents:
Description=CIFS network mount for sharename
mnt-cifs-sharename.automount with the contents:
Description=Automount for CIFS sharename
Now copy those two files into
/etc/systemd/system/ and reload the systemd daemon.
sudo cp -v ~/.cifs/mnt-cifs-sharename.mount /etc/systemd/system/
sudo cp -v ~/.cifs/mnt-cifs-sharename.automount /etc/systemd/system/
sudo systemctl daemon-reload
And enable only the automount unit:
sudo systemctl enable mnt-cifs-sharename.automount
Now when you browse to
/mnt/cifs/sharename, it will automatically try to connect and mount it via the CIFS kernel module. After two minutes of inactivity, it will automatically unmount it.
To make things more streamlined, you can create a “Favorite” in your file manager that points directly to
/mnt/cifs/sharename, and it will look like a local folder.
Look over every single option and contents. They will differ greatly on your setup. Everything must be consistent, or it will fail. I used “winnie” and “sharename” among other examples.
NOTE: Starting with kernel 5.17, you may need to include a third entry in your credentials file (“domain”) and set the domain to “workgroup” or whatever is configured in your SMB server, like so: