samba automount for systems with vpn access to samba server
lets suppose your user id is 1000
and your home directory is /home/mike
and we have a samba share on my.server.at.home
which is only reachable internally in your home LAN or through a vpn connection which you have set up on your laptop. the share name is Data
and you want to mount it to /home/mike/Data
via cifs
. since you are only sometimes connected to the vpn, it should automount as soon as you want to access it, which should succeed if you are connected to the VPN or to your local LAN.
in /etc/fstab
add the following line:
//my.server.at.home/Data /home/mike/Data cifs credentials=/home/mike/.smbcred,username=mike,uid=1000,gid=1000,file_mode=0664,dir_mode=0775,noauto,users,nofail,vers=1.0 0 0
and create a file /home/mike/.smbcred
with your login credentials in the following format:
username=mike password=totallySecretPassword
now change access permission to make sure only mike can read it:
chmod 600 /home/mike/smbcred
it should probably suffice to reload your systemd config, if that does not work, try to reboot
systemctl daemon-reload
now whenever you are in your VPN or LAN you can just open /home/mike/Data
and cifs will auto-mount