Samba CIFS file sharing (and NFS)

Samba server

Linux

sudo apt-get install samba
sudo smbpasswd -a user
<create the same user as unix>

Share permissions

Sharing is done from file browser, config is stored at:

cat /var/lib/samba/usershares/shared_dir
#VERSION 2
path=/home/user/shared_dir
comment=
usershare_acl=S-1-*-1001:F
guest_ok=n
sharename=Docs-Bertrand

# check current user shares:
net usershare info

# test current user shares:
smbclient -U user \\\\localhost\\shared_dir
smb: \> dir
  .                                   D        0  Wed Feb 14 12:35:55 2018
  ..                                  D        0  Tue Feb 27 14:42:00 2018

smbtree
sudo smbstatus

Mount / unmount shares

Linux (Shell)

sudo mount.cifs //host/share /media/smb -o username=user,password=***,uid=user,rw
sudo umount //host/share

Linux (fstab)

sudo mkdir /media/smb
echo "//host/share /media/smb cifs rw,user,credentials=/etc/samba/user@host.pswd,uid=user,gid=sambashare,noauto 0 0" | sudo tee -a /etc/fstab

sudo vi /etc/samba/user@host.pswd
username=user
password=pswd
domain=WORKGROUP
sudo chgrp sambashare /etc/samba/user@host.pswd
sudo chmod 640 /etc/samba/user@host.pswd

mount /media/smb

Windows

net use t: \\host\share <passwd> /user:WORKGROUP\user
net use \\host\share /delete

To set Windows hosts

Notepad C:\Windows\System32\drivers\etc\hosts

Add NFS support

Server

# Install NFS server
sudo apt-get install nfs-kernel-server 

# Add an NFS export
echo '/home/hwlab/Documents *(rw,all_squash,anonuid=1000,anongid=1000,sync)" | sudo tee -a /etc/exports
sudo /etc/init.d/nfs-kernel-server restart

Client

# Install NFS client
sudo apt-get install nfs-common

# Add an NFS share
sudo mkdir /media/poule
sudo mount -t nfs -o user poule:/opt /media/poule
# To force NFS v3 in case of problems with v4.x
# sudo mount -t nfs -o vers=3,user poule:/opt /media/poule
11-Dec-2018