Skip to content

Instantly share code, notes, and snippets.

@nerdybeast
Created April 25, 2020 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nerdybeast/ff954b971b4a233134805b9512eba7d0 to your computer and use it in GitHub Desktop.
Save nerdybeast/ff954b971b4a233134805b9512eba7d0 to your computer and use it in GitHub Desktop.
Automount a windows share (via cifs) on Ubuntu-based system
Problem: Need to access Windows share but only when on the company vpn.
- Tried mounting via fstab but the mount failed because I'm not automatically connected to the vpn when logged in
- Created a bash alias that simply mounts the share, the problem is that it's cumbersome to start the vpn then remember to run the mount command.
Autofs is a great option as it will automount that windows share only if I try and access it.
# Has to install it (Linux Mint 19)
sudo apt install autofs
# Opended the "/etc/auto.master" file the install created and added this line:
#Note: "/media" will hold our mount point meaning a directory will be created inside where the mount will be placed
# Note: we haven't yet created this "/etc/auto.company-media-share" file but we will
/media /etc/auto.company-media-share
# Created this file to hold the config for the company Windows share mout
sudo touch /etc/auto.company-media-share
# Added this line in /etc/auto.company-media-share
company-share -fstype=cifs,username=*****,password=*****,rw,nounix,noserverino ://media/company-share
# Created the actual mount point directory
# Note: we specified "/media" in the /etc/auto.master file BUT specified the actual mount point of "company-share" in /etc/auto.company-media-share
sudo mkdir /media/company-share
# Restarted the autofs service
sudo /etc/init.d/autofs reload
# Turned on the vpn and tested the mount
ls /media/company-share/images/
company-logo.png email-signature.png
Works!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment