Skip to content
Marcel Schmalzl edited this page Aug 22, 2024 · 16 revisions

Installation

sudo apt-get install samba-common samba tdb-tools

smb.conf

-> /etc/samba/smb.conf

Sample config (smb.conf)

# #################################
# Shares <my-network>
# #################################
[share]
    path = /home/admin/share/
    comment = Some share folder (no password needed)
    public = yes
    guest ok = yes
    
    # Not forcing a user was causing problems for my as guest
    force user = admin
    writeable = yes
    browsable = yes
    printable = no

[data]
    path = /mnt/data-disk-mount-path/
    comment = Data hard drive
    valid users = admin
    force user = admin
    writeable = yes
    browsable = yes
    printable = no

# This share grants user `vids` read access while `admin` still has read/write access
[hdd2]
   path = /mnt/vids/
   comment = Videos etc.
   valid users = vids admin
   force user = admin
   read only = yes
   write list admin
   browsable = yes
   printable = no

Test the config

Thes if the config is valid with testparm.

Samba socket vs. service

Socket starts demon on first connection; Service: on boot

Start/enable Samba services

Replace smbd.socket by smbd.service depending on what is used:

# Enable needed services (to be autostarted @reboot)
systemctl enable nmbd.service smbd.socket

# Start needed services (to be autostarted @reboot)
systemctl start nmbd.service smbd.socket

# Restart nmbd.service and smbd.socket to apply changes of `smb.conf`
systemctl restart nmbd.service smbd.socket

# Get status if everything works fine
systemctl status nmbd.service smbd.socket

Adding a user (for non-public/guest shares)

This user must exist as a UNIX user (-> sudo adduser --no-create-home --disabled-password --disabled-login <uname> (Without these options to prevent login via other channels (i.e. ssh, ...) you might introduce security risks) + set password with: passwd <pw>).

Samba has its own user database for access control (use this also to set a new password for an exiting user):

sudo smbpasswd -a <new_samba_user>

List samba users:

sudo pdbedit -L -v

You will then be prompted to enter and confirm a password

List/show samba shares

smbclient -L <share-domain> -U <usr-name>

Additional information

smb.conf

  • guest ok = yes == public = yes
  • printable: For printer sharing (otherwise = no)
  • Veto files: Prevent creation of certain files on the shares (in this example MacOS auto-generated files)
    • The share definitions can locally overwrite these settings
    veto files = /.DS_Store/._*/
    delete veto files = yes

List current users

sudo smbstatus

Thunar integration for samba network shares

Install gvfs-smb or gvfs-bin

Valid path for terminal (after mount) of a network share via gvfs (i.e. in a terminal session or in Thunar): /run/user/1000/gvfs/ (1000 can differ)

Troubleshooting

  • Unable to open new log file /usr/local/samba/var/log.ronda: No such file or directory
    • Execution of smbcontrol or smbd command when smbd runs as user uid (not root uid); When smbd runs as user uid, the log file cannot be opened again because there are no right to write to the directory.
    • Put this under the [global] section: logfile = /var/log/samba/log.%m
    • and make sure that /var/log/samba exists.
  • Invoking smbclient returns /etc/samba/smb.conf not found. Just create an empty file. Works for most cases.

Sources

Clone this wiki locally