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:
| |
Instead, I will just manually run:
| |
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:
| |
Give the permissions to the root user, as the credential file should explicitly readable/writeable to root:
| |
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:
What=//sever/nas, is the path of the remote server sharing the samba (e.g.//192.168.1.12/nas).Where=/mnt/nas, this is where the samba share will be mounted in the client side (e.g./home/your_username/nas).credentials=/etc/samba/credentials/nas, the credential file in the client side.uid=username,gid=usergroup, specify you username and usergroup in order to have read-write permissions. Otherwise, only root will be able to read-write.
Very important, the systemd unit name mnt-nas.mount MUST match the mountpoint name Where=/mnt/nas. See, in both cases it is nas.
| |
And that is it. I have nothing more to add this time.
Wait! This can also been applied to NFS shares, this is the snippet for mnt-share.mount (just change the server_ip):
| |
Usually, to simplify the mounting of the shares I have snippet aliases in my zsh config like:
| |
And also sym-link the mounting point to my home for easy access:
| |
If you found this content useful, please support me:
BTC: 1E2YjL6ysiPxRF4AEdXChpzpesRuyzgE1y