This comes directly from the archwiki, due to I got tired of mount the nas shares using dolphin (or similar) and have to go to the /run/media.... path everytime, or by manually running:

1
mount --mkdir -t cifs //SERVER/sharename /mnt/mountpoint -o username=username,password=password,workgroup=workgroup,iocharset=utf8,uid=username,gid=group

Instead, I will just manually run:

1
systemctl start mnt-nas.mount

Or enable it to mount it automatically during boot and to unmount I just have to stop the service.

Systemd unit configuration

First create a credential file, in the client, it should only contain the username and password that will be used to mount that specific samba share in /etc/samba/credentials/nas:

1
2
username=myuser
password=mypass

Give the permissions to the root user, as the credential file should explicitly readable/writeable to root:

1
2
3
chown root:root /etc/samba/credentials
chmod 700 /etc/samba/credentials
chmod 600 /etc/samba/credentials/nas

As you can see, you can have multiple credential file for multiple samba shares.

Now create the systemd unit under /etc/systemd/system/mnt-nas.mount. Here you can name the unit as you like.

Please note the following, that can be edited to fit your needs:

  1. What=//sever/nas, is the path of the remote server sharing the samba (e.g. //192.168.1.12/nas).
  2. Where=/mnt/nas, this is where the samba share will be mounted in the client side (e.g. /home/your_username/nas).
  3. credentials=/etc/samba/credentials/nas, the credential file in the client side.
  4. uid=username, specify you username in order to have read-write permissions. Otherwise, only root will be able to read-write. You can also specify a group instead of a user (e.g. gid=group)

Very important, the systemd unit name mnt-nas.mount MUST match the mountpoint name Where=/mnt/nas. See, in both cases it is nas.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
[Unit]
Description=Mount nas at boot

[Mount]
What=//server/nas
Where=/mnt/nas
Options=_netdev,credentials=/etc/samba/credentials/nas,uid=username,iocharset=utf8,rw
Type=cifs
TimeoutSec=30

[Install]
WantedBy=multi-user.target

And that is it. I have nothing more to add this time.

If you found this content useful, please support me:
BTC: 1E2YjL6ysiPxRF4AEdXChpzpesRuyzgE1y