Mounting CIFS with automount on Ubuntu 18:
-
Install the necessary applications/servers:
sudo apt install autofs smbclient cifs-utils
-
Configure autofs
create /etc/auto.cifs
, with this variant from auto.smb
, courtesy howtoforge
#!/bin/bash
# $Id$
# This file must be executable to work! chmod 755!
key="$1"
# Note: create a cred file for each windows/Samba-Server in your network
# which requires password authentification. The file should contain
# exactly two lines:
# username=user
# password=*****
# Please don't use blank spaces to separate the equal sign from the
# user account name or password.
credfile="/etc/auto.smb.$key"
# Note: Use cifs instead of smbfs:
mountopts="-fstype=cifs,file_mode=0644,dir_mode=0755,uid=user,gid=users"
smbclientopts=""
for P in /bin /sbin /usr/bin /usr/sbin
do
if [ -x $P/smbclient ]
then
SMBCLIENT=$P/smbclient
break
fi
done
[ -x $SMBCLIENT ] || exit 1
if [ -e "$credfile" ]
then
mountopts=$mountopts",credentials=$credfile"
smbclientopts="-A "$credfile
else
smbclientopts="-N"
fi
$SMBCLIENT $smbclientopts -gL $key 2>/dev/null \
| awk -v key="$key" -v opts="$mountopts" -F'|' -- '
BEGIN { ORS=""; first=1 }
/Disk/ { if (first) { print opts; first=0 };
gsub(/ /, "\\ ", $2);
sub(/\$/, "\\$", $2);
print " \\\n\t /" $2, "://" key "/" $2 }
END { if (!first) print "\n"; else exit 1 }
'
Note: you may need to modify the mountopts
, for an older ReadyNAS, I used:
mountopts="-fstype=cifs,file_mode=0644,dir_mode=0755,uid=my_user_name,gid=my_user_name,vers=1.0"
Set permissions: chmod 755 /etc/auto.cifs
Create /etc/auto.smb.FILESERVERNAME
with something like:
username=user
password=secret
Set permissions: chmod 600 /etc/auto.smb.*
edit /etc/auto.master
to add:
/cifs /etc/auto.cifs --timeout=60
- Fix for No DNS entries
My work network does not have a DNS entry for the file server I want. But I do
have an entry in my local /etc/hosts
file. I tried adding a name resolve order
line to /etc/samba/smb.conf
as recommended here,
but it didn't work. Looking at the docs, I ended up using dns proxy
.
[global]
dns proxy = yes
- Reload, Restart and enable autofs
sudo systemctl reload autofs.service
sudo systemctl restart autofs.service
sudo systemctl enable autofs.service
- Verify operation
list the directory with something like: ls /mnt/cifs/server/share
If things don't work, start digging into /var/log/syslog
and /var/log/samba/log*
(use ls -lrt
to find the most recently changed logs).
running automount -f -v
instead of with systemctl can be helpful
Running smbclient -L server -d 256
can be helpful. Using smbclient -L server -m SMBx
was key for me solving the Mount CIFS Host is down problem.