I have several CIFS shares on my NAS. One of those is my Documents share. I had been mounting it to the Documents directory in my home directory via the fstab. Works fine, however, I decided that I would rather use automount to mount the share on demand rather than it always being mounted.
I installed autofs, setup auto.master and auto.cifs. All looks good, I enable and start autofs and boom, the GUI dies. BTW, I use KDE Plasma. I spend a long time verifying syntax and making sure everything is configured correctly, but every time I try to automounting my cifs shared Documents to my home Documents dir, KDE crashes.
I created a directory in / called cifs. I then point the auto.cifs to mount Documents there, and it works just fine. I can see my data without issue.
Is there some reason why I can’t mount the CIFS share to my home Documents dir? As previously stated, it worked fine when I was doing it via fstab.
I don’t use automount instead I wrote my own script to do on demand mounts and umounts and created launchers on the DE dashboard to call each.
On client
Create group sharemount and add users allowed to mount shares.
Create file 01_sharemount in /etc/sudoers.d/ with perms 440 and this
content:
%sharemount ALL=NOPASSWD: /usr/sbin/mount.cifs, /bin/umount
Create credentials file in users home directory
/home/<username>/.samba/.<username> with directory perms 700 file perms
600
On server
Create corresponding users with passwords but no login access.
Create user mountable directories and entries in smb.conf
Now back on clients create the mount scripts in the users bin
directory with directory and file perms of 750
The mount script "sharemount":
#!/bin/bash
# sharemount <sharename 1> <sharename 2>
# This script will test for <servername> on the network and then mount shares or
# issue an error message
share="$@"
if ping -w 2 -c 1 <servername> && smbclient -NL <servername>; then
echo "<servername> is present"
for share in "$@" ; do
mkdir ~/$share
sudo mount.cifs -o username=$USERNAME,uid=$USERNAME,gid=$USERNAME,credentials=/home/$USERNAME/.samba/.$USERNAME //<servername>/$share ~/$share
done
else
echo "The server <servername> could not be reached. Is it on?"
fi
#################end of script###############
Now the umount script "umountsmb"
#!/bin/bash
# umount.cifs <share 1> <share 2>
# this program un-mounts network shares and then removes the mount point
share="$@"
for share in "$@" ; do
if [ -d ~/$share ]; then
sudo /bin/umount /home/$USERNAME/$share
wait=2
rmdir /home/$USERNAME/$share
wait=1
fi
done
################end of ummountsmb########################
Substitute $USER for $USERNAME in the noted scripts above as is something I defined long ago that is not necessary.
Since the shares are variables on the command line they can be changed as needed w/o changing the script.
sorry this isn’t a solution to automount. I tried it once and I think I had similar issues. It is probably due to the fact that root is mounting in the users home and this breaks things. If you can somehow run it as the user it may work.
This is how my auto.master looked when trying to mount to my home dir.
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
+auto.master
/home/<user> /etc/auto.cifs
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
+auto.master
/cifs/<user> /etc/auto.cifs --ghost
What is happening is that you have given the automounter complete control over /home/<user>. This means that subdirectories of /home/<user> other than Documents are no longer visible.
I think the solution is to use a direct map, instead of an indirect map, so your line in auto.master is
/- /etc/auto.direct
Remove the line with auto.cifs from auto.master.
Then in /etc/auto.direct, you have something like this:
In other words, all my automount rules, “maps”, are in one place: /etc/auto.master.d/
I do agree with @Whoever that direct mount or mount to elsewhere makes much more sense for Documents folder.
man auto.master writes:
[no]browse
This is an autofs specific option that is a pseudo mount option and so is given without a leading dash. Use of the browse option pre-creates mount point directories for indirect mount maps so the map keys can be seen in a directory listing without being mounted. Use of this option can cause performance problem if the indirect map is large so it should be used with caution. The internal program default is to enable browse mode for indirect mounts but the default installed configuration overrides this by setting BROWSE_MODE to “no” because of the potential performance problem. This option does the same as the deprecated--ghost option, the browse option is preferred because it is used by other autofs implementations.
The Documents is a directory that usually contains files and directories; it can have files.
It makes no difference whether Documents is a key under mount-point${HOME} in indirect map or a directly mounted directory.
The /home being a mount-point and each ${HOME} a key under it is also fine, because there will be no files directly in /home/. (One mounts directories, not files.)
However, the ${HOME} definitely does contain files, like the .cifscreds in OP example, so it cannot be a mount-point. (I might have seen an autofs mount-point that had some non-mounted content, but it was a mess that did require a hard reboot to get out of. KISS principle holds.)
There usually is an example smb.conf shipped with the samba packages. That usually explains the basics. I set my samba server up 20 years ago and have only made modifications as things didn’t work or after reading the documentation I saw that I had incorrect options or there was a better way. My script that I shared only knows the share names defined in the smb.conf. Other than that it has no other knowledge of the smb.conf settings. You really have to read the documentation. Googling for simple samba sharing set up will probably get you some examples. Back when there were bookstores I used a book called “Samba for Dummies”.
[bits]
path = /data/bits
browseable = no
writeable = yes
valid users = @k-r
force group = k-r
I created a group “k-r” and added the users allowed to access that share. The sharename in square brackets does not have to match the target directory in the path statement but it is what you would add to the sharemount command line w/o bracket.
I didn’t mention in my outline above that you need to populate the tdb.sam user database by adding the allowed users with the smbpasswd command. The name and password should match those created on the server.