knowledge/technology/applications/web/Samba.md
2023-12-04 11:02:23 +01:00

98 lines
2.9 KiB
Markdown

---
obj: application
website: https://www.samba.org
aliases: ["SMB"]
---
# Samba
Samba is an open-source software suite that provides seamless interoperability between [Linux](../../linux/Linux.md)/Unix servers and [Windows](../../windows/Windows.md)-based clients. It allows file and print services to be shared across a mixed network of [Windows](../../windows/Windows.md), [Linux](../../linux/Linux.md), and [macOS](../../macos/macOS.md) systems.
## Configuration
You configure samba with the file `/etc/samba/smb.conf`
### Structure:
The `smb.conf` file is structured into sections, each containing key-value pairs that define specific configurations. The sections are enclosed in square brackets (`[]`). The most commonly used section is `[global]`, which contains global settings applying to the entire Samba server. Other sections define individual shares or specific configurations.
### Common Sections:
1. **\[global]:**
- Contains global configurations applicable to the entire Samba server.
2. **\[sharename]:**
- Custom sections for defining specific shares.
### Global Options
```ini
[global]
# Workgroup
workgroup = WORKGROUP
# User needs to logon before connection
security = user
# Server description
server string = descriptive string
# Set minimum protocol to SMB3
server min protocol = SMB3_00
# Encrypt passwords in connection
encrypt passwords = yes
# ReadWrite Raw
read raw = Yes
write raw = Yes
```
### Share Options
```ini
[MyShare]
# Set share to readonly
read only = no
# Filesystem path
path = /my/share
# Users allowed to access this share
valid users = user
# Enable the share to be seen when connecting
browseable = yes
# Enable writing to the share
writeable = yes
# File and Directory permissions for creation.
create mode = 0750
directory mode = 0750
```
#### Recycle Bin
To enable a recycle bin on your share, add this to the config:
```ini
# Enable recycle bin
vfs object = recycle
# Set recycle bin location
recycle:repository = /my/share/.Trash
# Directory permissions
recycle:directory_mode = 0750
# Keep the directory structure when something is deleted
recycle:keeptree = Yes
recycle:touch = Yes
# Set max file size
recycle:maxsize = 100000000
# Enable versioning
recycle:versions = no
# Exclude files from versioning
recycle:noversions = *.ini | *.dat
# Exclude from recycle bin
recycle:exclude = *.TMP | *.tmp | ~$*.doc
recycle:exclude_dir = tmp | temp | cache
```
#### Snapshots
If you want to expose snapshots (for example from [ZFS](../../linux/filesystems/ZFS.md)), add this config:
```ini
# Enable snapshots
vfs object = shadow_copy2
# Directory which holds the snapshots (relative to share)
shadow:snapdir = .zfs/snapshot
# Snapshot format (date and time)
shadow:format = SNAP_%Y.%m.%d-%H.%M.%S
# Snapshot sorting
shadow:sort = desc
```
## User Authentication
### 1. **User Mapping:**
- Samba maps local system users to SMB users. Use the `smbpasswd` command to set passwords for SMB users.