Samba ermöglicht Dateifreigaben zwischen Linux und Windows-Systemen. Es implementiert das SMB/CIFS-Protokoll und bietet nahtlose Integration in Windows-Netzwerke.
Installation
Debian/Ubuntu
apt update
apt install samba samba-common-binCentOS/RHEL
dnf install samba samba-client samba-commonService aktivieren
systemctl enable --now smbd nmbd
systemctl status smbdGrundkonfiguration
Konfigurationsdatei
# /etc/samba/smb.conf
[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = fileserver
security = user
map to guest = bad user
dns proxy = no
# Logging
log file = /var/log/samba/log.%m
max log size = 1000
log level = 1
# Performance
socket options = TCP_NODELAY IPTOS_LOWDELAYKonfiguration testen
testparmBenutzer einrichten
Samba-Benutzer erstellen
# Linux-Benutzer erstellen (falls nicht vorhanden)
useradd -M -s /sbin/nologin sambauser
# Samba-Passwort setzen
smbpasswd -a sambauser
# Benutzer aktivieren
smbpasswd -e sambauserBenutzer verwalten
# Alle Samba-Benutzer auflisten
pdbedit -L
# Detaillierte Liste
pdbedit -L -v
# Benutzer löschen
smbpasswd -x sambauserFreigaben erstellen
Einfache Freigabe
# /etc/samba/smb.conf
[Daten]
path = /srv/samba/daten
browseable = yes
read only = no
valid users = sambauser
create mask = 0644
directory mask = 0755Öffentliche Freigabe
[Public]
path = /srv/samba/public
browseable = yes
read only = no
guest ok = yes
create mask = 0666
directory mask = 0777Versteckte Freigabe
[Admin$]
path = /srv/samba/admin
browseable = no
read only = no
valid users = adminNur-Lesen-Freigabe
[Archiv]
path = /srv/samba/archiv
browseable = yes
read only = yes
write list = adminVerzeichnisse vorbereiten
# Verzeichnisse erstellen
mkdir -p /srv/samba/{daten,public,archiv}
# Berechtigungen setzen
chown -R nobody:nogroup /srv/samba/public
chmod -R 777 /srv/samba/public
chown -R sambauser:sambagroup /srv/samba/daten
chmod -R 755 /srv/samba/daten
# Service neu starten
systemctl restart smbdGruppenfreigaben
Gruppe erstellen
# Linux-Gruppe
groupadd sambagroup
usermod -aG sambagroup sambauser
usermod -aG sambagroup otheruserGruppenfreigabe
[Team]
path = /srv/samba/team
browseable = yes
read only = no
valid users = @sambagroup
force group = sambagroup
create mask = 0664
directory mask = 0775# Verzeichnis vorbereiten
mkdir /srv/samba/team
chown root:sambagroup /srv/samba/team
chmod 2775 /srv/samba/team # SGIDZugriff testen
Von Linux
# Freigaben auflisten
smbclient -L //server -U sambauser
# Verbinden
smbclient //server/Daten -U sambauser
# Befehle
smb: \> ls
smb: \> put localfile.txt
smb: \> get remotefile.txt
smb: \> exitMounten
# Manuell
mount -t cifs //server/Daten /mnt/samba -o username=sambauser,password=passwort
# Mit Credentials-Datei
# /etc/samba/credentials
username=sambauser
password=passwort
chmod 600 /etc/samba/credentials
mount -t cifs //server/Daten /mnt/samba -o credentials=/etc/samba/credentialsfstab-Eintrag
# /etc/fstab
//server/Daten /mnt/samba cifs credentials=/etc/samba/credentials,uid=1000,gid=1000,_netdev 0 0Von Windows
Datei-Explorer → \\server\Daten
Oder: Netzlaufwerk verbinden (Z:)Erweiterte Optionen
Papierkorb
[Daten]
path = /srv/samba/daten
vfs objects = recycle
recycle:repository = .recycle
recycle:keeptree = yes
recycle:versions = yes
recycle:maxsize = 0
recycle:exclude = *.tmp, *.tempVolltext-Indexierung
[Daten]
vfs objects = full_audit
full_audit:prefix = %u|%I|%m|%S
full_audit:success = mkdir rename unlink rmdir pwrite
full_audit:failure = none
full_audit:facility = local5
full_audit:priority = noticeVersionierung
[Daten]
vfs objects = shadow_copy2
shadow:snapdir = .snapshots
shadow:basedir = /srv/samba/daten
shadow:sort = descZugriffszeitsteuerung
[Zeitgesteuert]
path = /srv/samba/zeitgesteuert
valid users = @mitarbeiter
# Nur während Arbeitszeiten
# Benötigt externes Tool wie cronActive Directory-Integration
Samba als AD-Mitglied
# Pakete installieren
apt install winbind libpam-winbind libnss-winbind krb5-config
# /etc/samba/smb.conf
[global]
workgroup = DOMAIN
security = ADS
realm = DOMAIN.LOCAL
winbind use default domain = yes
winbind enum users = yes
winbind enum groups = yes
idmap config * : backend = tdb
idmap config * : range = 3000-7999
idmap config DOMAIN : backend = rid
idmap config DOMAIN : range = 10000-999999Domain beitreten
# Kerberos-Ticket holen
kinit administrator@DOMAIN.LOCAL
# Domain beitreten
net ads join -U administrator
# Services neu starten
systemctl restart smbd winbind
# Test
wbinfo -u # Benutzer auflisten
wbinfo -g # Gruppen auflistenAD-Benutzer-Freigabe
[ADShare]
path = /srv/samba/adshare
read only = no
valid users = @"DOMAIN\Domain Users"Firewall
UFW
ufw allow samba
# Oder einzeln:
ufw allow 137/udp
ufw allow 138/udp
ufw allow 139/tcp
ufw allow 445/tcpiptables
iptables -A INPUT -p udp -m multiport --dports 137,138 -j ACCEPT
iptables -A INPUT -p tcp -m multiport --dports 139,445 -j ACCEPTPerformance-Optimierung
Socket-Optionen
[global]
socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=131072 SO_SNDBUF=131072Async-IO
[global]
aio read size = 16384
aio write size = 16384Oplocks
[Daten]
oplocks = yes
level2 oplocks = yesSicherheit
Verschlüsselung
[global]
server min protocol = SMB2
smb encrypt = requiredZugriffsbeschränkung
[global]
hosts allow = 192.168.1. 10.0.0.
hosts deny = ALL
[Daten]
hosts allow = 192.168.1.100, 192.168.1.101Audit-Logging
[global]
vfs objects = full_audit
full_audit:prefix = %u|%I
full_audit:success = connect disconnect opendir mkdir rmdir open close read write rename unlink
full_audit:failure = connect
full_audit:facility = local5
full_audit:priority = noticeTroubleshooting
Verbindungsprobleme
# Samba-Status
systemctl status smbd nmbd
# Logs prüfen
tail -f /var/log/samba/log.smbd
# Netzwerk testen
smbclient -L //localhost -U sambauserBerechtigungsprobleme
# Linux-Berechtigungen prüfen
ls -la /srv/samba/
# SELinux (CentOS/RHEL)
setsebool -P samba_enable_home_dirs on
setsebool -P samba_export_all_rw onPasswort-Synchronisation
# Samba-Passwort zurücksetzen
smbpasswd -a username
# Status prüfen
pdbedit -L -v -u usernameZusammenfassung
| Befehl | Funktion | |--------|----------| | testparm | Konfiguration prüfen | | smbpasswd -a user | Benutzer hinzufügen | | pdbedit -L | Benutzer auflisten | | smbclient -L //server | Freigaben anzeigen | | smbstatus | Aktive Verbindungen |
| Datei | Beschreibung | |-------|--------------| | /etc/samba/smb.conf | Hauptkonfiguration | | /var/log/samba/ | Log-Dateien | | /var/lib/samba/ | Datenbanken |
Fazit
Samba ist die Standardlösung für Dateifreigaben in gemischten Linux/Windows-Umgebungen. Die Konfiguration über smb.conf ist flexibel und ermöglicht einfache bis komplexe Setups. Für reine Linux-Umgebungen ist NFS performanter, aber für Windows-Integration führt kein Weg an Samba vorbei. Active Directory-Integration macht Samba zum vollwertigen Fileserver im Unternehmensumfeld.