Skip to content

Instantly share code, notes, and snippets.

@teosoft123
Forked from rbb/README.md
Created November 27, 2019 23:24
Show Gist options
  • Select an option

  • Save teosoft123/568bfb66e55cef608acadfd8b0d1c398 to your computer and use it in GitHub Desktop.

Select an option

Save teosoft123/568bfb66e55cef608acadfd8b0d1c398 to your computer and use it in GitHub Desktop.

Revisions

  1. @rbb rbb created this gist Oct 18, 2018.
    107 changes: 107 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,107 @@
    Mounting CIFS with automount on Ubuntu 18:

    1. Install the necessary applications/servers:

    sudo apt install autofs smbclient cifs-utils

    2. Configure autofs

    create `/etc/auto.cifs`, with this variant from `auto.smb`, courtesy [howtoforge](https://www.howtoforge.com/accessing_windows_or_samba_shares_using_autofs)

    ```
    #!/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
    ```

    3. 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](https://serverfault.com/questions/609365/cifs-mount-in-fstab-succeeds-on-ip-fails-on-hostname-written-in-etc-hosts),
    but it didn't work. Looking at the docs, I ended up using `dns proxy`.

    ```
    [global]
    dns proxy = yes
    ```

    4. Reload, Restart and enable autofs

    ```
    sudo systemctl reload autofs.service
    sudo systemctl restart autofs.service
    sudo systemctl enable autofs.service
    ```

    5. 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](https://serverfault.com/questions/414074/mount-cifs-host-is-down) problem.