Skip to content

Instantly share code, notes, and snippets.

@kyamagu
Created August 28, 2017 03:57
Show Gist options
  • Save kyamagu/5de714c831431b4e8002782113b91769 to your computer and use it in GitHub Desktop.
Save kyamagu/5de714c831431b4e8002782113b91769 to your computer and use it in GitHub Desktop.

SMBNetFS

Install and setup

sudo apt-get install smbnetfs
mkdir ~/.smb
cp /etc/smbnetfs/smbnetfs.conf ~/.smb
cp /etc/samba/smb.conf ~/.smb
tee ~/.smb/smbnetfs.auth <<EOF
auth HOSTNAME USERNAME PASSWORD
EOF
chmod 600 ~/.smb/smbnetfs.auth

Usage

Mount

mkdir MOUNTPOINT
smbnetfs MOUNTPOINT
ls MOUNTPOINT/WORKGROUP
ls MOUNTPOINT/HOSTNAME
ls MOUNTPOINT/USERNAME:PASSWORD@HOSTNAME/SHAREPOINT

Unmount

fusermount -u MOUNTPOINT

DNS setup

sudo tee -a /etc/resolvconf/resolv.conf.d/base <<EOF
search mydomain.com
nameserver 192.168.0.1
EOF
sudo resolveconf -u
@pratikbin
Copy link

Thanks it works for me

@michaeldexter
Copy link

Do newer versions need a smbnetfs.host file?

I increased the debug level and it was mentioned as missing, so I created it:

vi ~/.smb/smbnetfs.host
host 10.0.0.20 visible=true

This allowed the mount to work for me on FreeBSD 14.0.

@Svedrin
Copy link

Svedrin commented Mar 14, 2024

I got it to work using Kerberos authentication:

  1. apt-get install krb5-user

  2. Configure /etc/krb5.conf:

     [libdefaults]
     default_realm = YOUR.AD.DOMAIN.IN.UPPERCASE
     default_keytab_name = /etc/krb5.keytab
     default_tkt_enctypes = rc4-hmac des-cbc-crc des-cbc-md5
     default_tgs_enctypes = rc4-hmac des-cbc-crc des-cbc-md5
    
     [domain_realm]
     .your.ad.domain.in.lowercase = YOUR.AD.DOMAIN.IN.UPPERCASE
     your.ad.domain.in.lowercase = YOUR.AD.DOMAIN.IN.UPPERCASE
    
  3. Get a Kerberos ticket using kinit -r28d your.user@YOUR.AD.DOMAIN.IN.UPPERCASE

  4. Validate that it works using smbclient -k -U your.user@YOUR.AD.DOMAIN.IN.UPPERCASE -L //hostname.your.ad.domain.in.whatevercase

  5. Run smbnetfs ~/mountpoint

  6. Access Windows stuff using ls ~/mountpoint/hostname.your.ad.domain.in.whatevercase/sharename/folder/file.txt

Step 3 fetches a renewable Kerberos Ticket, which I combined with an hourly cronjob to renew it:

0 * * * kinit -r28d -R your.user@YOUR.AD.DOMAIN.IN.UPPERCASE

The ~/mountpoint dir was empty, but accessing the files worked regardless. Adding a ~/.smb/smbnetfs.host file made my target host appear in the directory so that I can use tab completion for convenience, but file access worked without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment