# Automount nas cifs share

**URL:** <https://forums.rockylinux.org/t/automount-nas-cifs-share/12192>\
**Category:** Rocky Linux Help & Support\
**Created:** [December 15, 2023, 11:41pm UTC](https://forums.rockylinux.org/t/automount-nas-cifs-share/12192 "2023-12-15T23:41:08Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![rosede](https://avatars.discourse-cdn.com/v4/letter/r/cc9497/32.png) [@rosede](https://forums.rockylinux.org/u/rosede)\
**Post date:** [December 15, 2023, 11:41pm UTC](https://forums.rockylinux.org/t/automount-nas-cifs-share/12192/1 "2023-12-15T23:41:08Z")

</div>

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.

Thanks

---

<div class="post-metadata">

**Author:** ![jbkt23](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jbkt23](https://forums.rockylinux.org/u/jbkt23)\
**Post date:** [December 16, 2023, 4:43am UTC](https://forums.rockylinux.org/t/automount-nas-cifs-share/12192/2 "2023-12-16T04:43:19Z")

</div>

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.

```Outline

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.

---

<div class="post-metadata">

**Author:** ![Whoever](https://avatars.discourse-cdn.com/v4/letter/w/9de053/32.png) [@Whoever](https://forums.rockylinux.org/u/Whoever)\
**Post date:** [December 16, 2023, 10:48pm UTC](https://forums.rockylinux.org/t/automount-nas-cifs-share/12192/3 "2023-12-16T22:48:49Z")

</div>

What do your auto.master and auto.cifs look like?

I suspect that the automounter is mounting the CIFS share in a different directory to the one you expect and that’s what is interfering with KDE.

---

<div class="post-metadata">

**Author:** ![rosede](https://avatars.discourse-cdn.com/v4/letter/r/cc9497/32.png) [@rosede](https://forums.rockylinux.org/u/rosede)\
**Post date:** [December 17, 2023, 3:34pm UTC](https://forums.rockylinux.org/t/automount-nas-cifs-share/12192/4 "2023-12-17T15:34:29Z")

</div>

Thanks for this script. I’ll look at it and give it a try.

---

<div class="post-metadata">

**Author:** ![rosede](https://avatars.discourse-cdn.com/v4/letter/r/cc9497/32.png) [@rosede](https://forums.rockylinux.org/u/rosede)\
**Post date:** [December 17, 2023, 3:43pm UTC](https://forums.rockylinux.org/t/automount-nas-cifs-share/12192/5 "2023-12-17T15:43:18Z")

</div>

This is how my auto.master looked when trying to mount to my home dir.

```auto
#
# 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

```

This is how my auto.cifs looks:

```auto
Documents -fstype=cifs,rw,noperm,credentials=/home/<user>/.cifscreds,vers=3.0 ://nas01/Documents

```

Changing auto.master to this works

```auto
#
# 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

```

Thanks

---

<div class="post-metadata">

**Author:** ![Whoever](https://avatars.discourse-cdn.com/v4/letter/w/9de053/32.png) [@Whoever](https://forums.rockylinux.org/u/Whoever)\
**Post date:** [December 17, 2023, 5:32pm UTC](https://forums.rockylinux.org/t/automount-nas-cifs-share/12192/6 "2023-12-17T17:32:36Z")

</div>

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

```auto
/- /etc/auto.direct
```

Remove the line with auto.cifs from auto.master.

Then in /etc/auto.direct, you have something like this:

```auto
/home/<user>/Documents -fstype=cifs,rw,noperm,credentials=/home/<user>/.cifscreds,vers=3.0 ://nas01/Doc
```

The alternative solution is to mount Documents in /cifs/\<user\> and make your Documents directory a symbolic link to /cifs/\<user\>/Documents

---

<div class="post-metadata">

**Author:** ![jlehtone](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@jlehtone](https://forums.rockylinux.org/u/jlehtone)\
**Post date:** [December 18, 2023, 8:50am UTC](https://forums.rockylinux.org/t/automount-nas-cifs-share/12192/7 "2023-12-18T08:50:16Z")

</div>

One does not need to edit the auto.master at all. Mine is edited a bit though, but the statements that I have are in the default too:

```auto
$ cat /etc/auto.master
# ansible #
+dir:/etc/auto.master.d
+auto.master

```

The `dir` makes autofs read all `/etc/auto.master.d/*.autofs` files.  
I can thus have:

```auto
$ cat /etc/auto.master.d/local.autofs 
# ansible #
/- /etc/auto.master.d/auto.direct --timeout=300
/home /etc/auto.master.d/auto.home --timeout=300 nobrowse
/data /etc/auto.master.d/auto.data --timeout=300 browse

```

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.

---

<div class="post-metadata">

**Author:** ![rosede](https://avatars.discourse-cdn.com/v4/letter/r/cc9497/32.png) [@rosede](https://forums.rockylinux.org/u/rosede)\
**Post date:** [December 21, 2023, 8:45pm UTC](https://forums.rockylinux.org/t/automount-nas-cifs-share/12192/8 "2023-12-21T20:45:03Z")

</div>

Thank you for these great options. I’ll give them a try.

---

<div class="post-metadata">

**Author:** ![jlehtone](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@jlehtone](https://forums.rockylinux.org/u/jlehtone)\
**Post date:** [December 22, 2023, 7:38am UTC](https://forums.rockylinux.org/t/automount-nas-cifs-share/12192/9 "2023-12-22T07:38:23Z")

</div>

> [@jlehtone](#):
>
> makes much more sense for _Documents_ folder

Perhaps I should expand my rationale for that:

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.)

---

<div class="post-metadata">

**Author:** ![rosede](https://avatars.discourse-cdn.com/v4/letter/r/cc9497/32.png) [@rosede](https://forums.rockylinux.org/u/rosede)\
**Post date:** [January 1, 2024, 7:24pm UTC](https://forums.rockylinux.org/t/automount-nas-cifs-share/12192/10 "2024-01-01T19:24:45Z")

</div>

I want to try to give your script a go. I’m not very familiar with the smb.conf file. What entries should I put in there?

Thanks

---

<div class="post-metadata">

**Author:** ![jbkt23](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jbkt23](https://forums.rockylinux.org/u/jbkt23)\
**Post date:** [January 1, 2024, 10:24pm UTC](https://forums.rockylinux.org/t/automount-nas-cifs-share/12192/11 "2024-01-01T22:24:58Z")

</div>

> What entries should I put in there?

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”.

---

<div class="post-metadata">

**Author:** ![rosede](https://avatars.discourse-cdn.com/v4/letter/r/cc9497/32.png) [@rosede](https://forums.rockylinux.org/u/rosede)\
**Post date:** [January 2, 2024, 12:47am UTC](https://forums.rockylinux.org/t/automount-nas-cifs-share/12192/12 "2024-01-02T00:47:46Z")

</div>

Yes I was searching for some examples. Reading [smb.conf](https://www.samba.org/samba/docs/current/man-html/smb.conf.5.html), I see a section labeled " USERSHARES". I guessing you have something setup along those lines?

Thanks for sharing your script. I appreciate it.

---

<div class="post-metadata">

**Author:** ![jbkt23](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jbkt23](https://forums.rockylinux.org/u/jbkt23)\
**Post date:** [January 2, 2024, 3:01pm UTC](https://forums.rockylinux.org/t/automount-nas-cifs-share/12192/13 "2024-01-02T15:01:39Z")

</div>

Here is an example share:

```auto
[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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/rockylinux/original/1X/91b7219eec10e30013422e4df76c1d898711a5d5.svg) [@system](https://forums.rockylinux.org/u/system)\
**Post date:** [March 2, 2024, 3:02pm UTC](https://forums.rockylinux.org/t/automount-nas-cifs-share/12192/14 "2024-03-02T15:02:23Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
