os/linux/ SMB


Mounting

mount -t cifs -o username=USERNAME,password=PASSWORD //MACHINE/SHARE /mnt/TARGET

or

mount -t cifs -o user=USERNAME,pass=PASSWORD //MACHINE/SHARE /mnt/TARGET

Samba share

In smb.conf:

[disk1]
    path = /path/to/disk
    available = yes
    read only = no
    browsable = yes
    public = yes
    writable = no
    guest ok = yes
    create mask = 0644
    directory mask = 0755

Allowing users

smbpasswd -a benjamin

If you don't do this, and you have log level = 3 in your smb.conf, you'll see the following error (and from the client you will get permission denied):

string_to_sid: SID benjamin is not in a valid format

Network visibility

To make your samba-enabled Linux box visible in the Network browser in Windows, we need a little helper. You get it from https://github.com/Netgear/wsdd2

git clone https://github.com/Netgear/wsdd2
cd wsdd2
make
sudo make install
sudo systemctl enable wsdd2
sudo systemctl start wsdd2

A typical smbd.conf

My use case is generally a NAS or similar for a home network in a one-person flat. I have a Thinkpad T420 with a broken screen running Kubuntu acting as a server, and some HP microservers running Ubuntu Server for other NAS duties. So convenience is the main priority and the kind of security you want for multiuser systems is not.

# ... stuff from the standard smb.conf that comes with ubuntu

[global]
  allow insecure wide links = yes

  follow symlinks = yes
  wide links = yes
  unix extensions = yes

# ... other stuff omitted ...

[media]
  path = /media/john/
  available = yes
  valid users = john
  force user = john
  read only = yes
  browsable = yes
  public = no
  writable = no

[data]
  path = /data
  available = yes
  valid users = john
  force user = john
  read only = yes
  browsable = yes
  public = yes
  writable = no

[music]
  path = /data/music
  available = yes
  valid users = john
  force user = john
  read only = no
  browsable = yes
  public = yes
  writable = yes

[pod]
  path = /data/music/podcasts
  available = yes
  valid users = john
  force user = john
  read only = no
  browsable = yes
  public = yes
  writable = yes

[hdd]
  path = /media/john/t420b_hdd1
  available = yes
  valid users = john
  force user = john
  read only = yes
  browsable = yes
  public = yes
  writable = no

[hdd2]
  path = /media/john/t420b_hdd2
  available = yes
  valid users = john
  force user = john
  read only = yes
  browsable = yes
  public = yes
  writable = no

[hdd3]
  path = /media/john/t420b_hdd3
  available = yes
  valid users = john
  force user = john
  read only = yes
  browsable = yes
  public = yes
  writable = no

[root]
  path = /
  available = yes
  valid users = john
  force user = john
  read only = yes
  browsable = yes
  public = yes
  writable = no

[john]
  path = /home/john
  available = yes
  valid users = john
  force user = john
  read only = yes
  browsable = yes
  public = yes
  writable = no
  follow symlinks = yes
  wide links = yes

[inc]
  path = /media/john/t420b_hdd1/inc
  available = yes
  valid users = john
  force user = john
  read only = no
  browsable = yes
  public = yes
  writable = yes

[obs]
  path = /data/obsidian
  available = yes
  valid users = john
  force user = john
  read only = no
  browsable = yes
  public = yes
  writable = yes

[index]
  path = /home/john/index
  available = yes
  valid users = john
  force user = john
  read only = no
  browsable = yes
  public = yes
  writable = no

[books]
  path = /media/john/t420b_hdd1/books
  available = yes
  valid users = john
  force user = john
  read only = no
  browsable = yes
  public = yes
  writable = yes