Distroname and release: Ubuntu

Autofs on Ubuntu

autofs can be used to automount cifs mounts (and others), when ever its accessed.
There is one major caveat . Password is stored Unencrypted on the harddrive! BAD! If you can live with this, then go ahead.

Start by installing autofs

apt-get install autofs cifs-utils
Create the auto master, include directory.
sudo mkdir /etc/auto.master.d
Create an new autofs file which will be loaded by autofs.
Notice that first part is the "initial" mount point, which will be followed by the share name. (/mnt/cifs/sharename).
IMPORTANT mount point must NOT end with /
/etc/auto.master.d/cifs.autofs 
/mnt/cifs /etc/autofs.cifs
Create the mount file for autofs.
MYMOUNT is the autofs name, which we then can access by "/mnt/cifs/MYMOUNT/"
Note: #vers=2.0 might not be needed.
But if you get an error with "automount[21074]: >> mount error(112): Host is down", its most likely so.
This error might only show with debug enabled!
/etc/autofs.cifs
MYMOUNT -fstype=cifs,rw,credentials=/home/user/.cifscredentials,file_mode=0777,dir_mode=0777,vers=2.0 ://SERVERNAME/PATH/To/Folder
Create an new file with username and password.
/home/user/.cifscredentials
username=user
password=secretpass
Set correct permissions in this file, so only your user can read it.
chmod 400 /home/user/.cifscredentials
restart autofs
/etc/init.d/autofs restart
Now you should be able to view the content by going to /mnt/cifs/MYMOUNT/.

Remember, we set these "paths" previously!
It's likely it will not autocomplete for the MYMOUNT folder, but it should show up, if you just type it manually.

ls -l /mnt/cifs/MYMOUNT/
If it aint working, start with debug
/etc/default/autofs
OPTIONS="--debug"

Do not trust the authors words! POC, tests and experience is key

Copyright LinuxLasse.net 2009 - 2024 All Rights Reserved.

Valid HTML 4.01 Strict Valid CSS!