My preferred way is to add a systemd automount to /etc/fstab
Something like this:
//servername/sharename /path/to/mount cifs x-systemd.automount,x-systemd.idle-timeout=1min,rw,uid=yourusername,gid=yourgroupname,credentials=/etc/samba/private/sharename.cred,iocharset=utf8,vers=2.0 0 0
For example(I am using mlt as your username, if it is something else, use that instead):
First create somewhere to mount it:
sudo mkdir /mnt/server
Create a file called /etc/samba/private/server.cred
with this as the contents
username=myuser
password=mypass
Replace myuser
and mypass
with your username and password for the smb share.
Then add this to the bottom of your /etc/fstab
//192.168.1.59 /mnt/server cifs x-systemd.automount,x-systemd.idle-timeout=1min,rw,uid=mlt,gid=mlt,credentials=/etc/samba/private/server.cred,iocharset=utf8,vers=2.0 0 0
Before rebooting, test it out by typing:
sudo mount /mnt/server
If it worked, you should see the contents of your share at /mnt/server
.
The nice thing about a systemd automount is that if the server isn’t available it should’t cause anything to break or hang.
Also, you can mount it anyplace you want. /mnt/server
is just an example.