Setting up /etc/fstab entry for SMB (Windows) file share can be tricky. Here I document options that I use. Today many file managers will offer built-in support for mounting SMB shares using FUSE userland file system support instead.
We will put /etc/fstab entry like below:
//<IP or host>/<share> /mnt/<host>/<share> cifs user=<login>,seal,vers=3.0,soft,user,noauto,nosuid,nodev,noexec 0 0
Where:
You will need to create /mnt/<host>/<share> directory with mkdir as root.
Extra options:
Now you can run mount /mnt/<host>/<share> as a regular user. You will be prompted for the share user password.
If your system uses symlink approach for mtab (/etc/mtab -> /proc/self/mounts) then you won't be able to umount your share without using sudo. See Option "user" work for mount, not for umount.
If your system hangs on shut down or reboot after you have mounted the share it may be because your wi-fi connection goes down before the file systems are un-mounted.
If you use pass password manager you can use this script to automate the mounting process:
#!/bin/sh
expect \
-c "spawn mount /mnt/<host>/<share>" \
-c 'set spawn_id_mount $spawn_id' \
-c 'expect "Password for" {log_user 0; spawn -noecho pass <password path>; expect -re "(.*?)\n"; set pass "$expect_out(1,string)"; wait; set spawn_id $spawn_id_mount; send -- "$pass"; log_user 1; send_user -- "*****"} eof {exit}' \
-c 'interact'
Remember to replace <host>, <share> and <password path> with path to the share password in you manager. You may need to tweak the script for different system language locales.