====== Samba ====== [[wpde>Samba_(Software)|Samba]] ist eine freie Software-Suite, die (das von [[windows:Windows]] verwendete) [[netzwerke:SMB bzw. CIFS|Server-Message-Block-Protokoll (SMB) bzw. neu: CIFS]] für Unix-artige Systeme verfügbar macht. siehe auch: **[[netzwerke:Drucken im Netz]]**, [[shellscripts:samba-print-pdf]] [[http://www.oreilly.de/german/freebooks/samba2ger/ch05.html|Samba, 2. Auflage GNU FDL]] {{:samba:samba_rechteabbildung.png|Samba Rechteabbildung aus: O`Reilly: Samba; Lizenz GNU FDL}} ^ Nützliche Programme zu Samba ^^ ^ Programm ^ Funktion ^ | nmblookup | schlägt NetBIOS-Namen nach, z.B. nmblookup -U IP -A IP | | smbstatus | zeigt den aktuellen Status von Samba | | testparm | prüft die syntaktische Richtigkeit (geänderter) Einstellungen | | smbpasswd | ändert die Passwörter der Samba-Benutzer (in ''/etc/samba/smbpasswd''). Dieses backend wird übrigens in aktuellen Samba-Versionen nicht mehr standardmäßig benutzt sondern muss mit "''passdb backend = smbpasswd''" explizit angegeben werden | | pdbedit | Editiert das tdb-backend (Datei liegt in ''/var/lib/samba/passdb.tdb''). ''pdbedit -L'' listet Benutzer auf. | ===== Links ===== * **[[http://wiki.ubuntuusers.de/Samba_Server|Samba Server]]** * [[http://www.nicht-blau.de/2010/12/28/howto-samba-3-5-6-pdc-primary-domain-controller-und-windows-7-2/#more-580|HowTo: Samba 3.5.6 PDC (Primary Domain Controller) und Windows 7]] * [[http://gertranssmb3.berlios.de/output/index.html|Samba-HOWTO-Sammlung]] * [[http://www.64-bit.de/dokumentationen/netzwerk/b/001/25741-inh.htm#TopOfPage|Samba in 21 Tagen]] * [[http://www.linux-magazin.com/videos/samba_freie_alternative_zu_windows_servern|Vortrag - Samba: Freie Alternative zu Windows-Servern]] * [[http://www.samba.org/|Samba Homepage]] * [[http://www.howtoforge.com/samba_domaincontroller_setup_ubuntu_6.10|SAMBA (Domaincontroller) Server For Small Workgroups With Ubuntu 6.10]] * [[http://de4.samba.org/samba/docs/Samba3-HOWTO.pdf|Samba3-Howto]] * [[http://gentoo-wiki.com/HOWTO_Implement_Samba_as_your_PDC|HOWTO Implement Samba as your PDC]] * [[http://www.netigator.de/netigator/live/show.php3?id=47&aid=10062175|Open-Source-Server Samba Server 3 als PDC ]] * [[http://www.heise.de/newsticker/meldung/97487/|Freier CIFS-Server von Alfresco]] * [[http://jaka.kubje.org/wp/2007/05/14/unix-samba-password-sync-on-debian-etch/|Unix and Samba password sync on Debian Etch]] * [[https://portal.enterprisesamba.com/users/sign_up|Sernet bietet kostenlose Samba-4-Pakete]] ===== Syncronisation der Passwörter ===== Wenn ein Benutzer sein Passwort ändert, muss das im Normalfall an 2-3 Stellen erfolgen - unter [[windows:Windows]] - bei Samba (''smbpasswd'') - unter [[linux:Linux]] (mit ''passwd'') Lösen lässt sich das Problem indem man - entweder Login-Namen, Passwörter und andere Benutzerspezifische Daten mit einem [[netzwerke:LDAP]]-Server verwaltet. Darauf kann mit Samba und [[linux:PAM]] zugegriffen werden. - oder einen [[windows:Windows]]-Server dazu benutzt. Dann muss Samba (mit ''security = domain'' oder ''security = ads'' und ''winbindd'') als auch [[linux:PAM]] passend konfiguriert werden. ===== Konfiguration ===== Die Einstellungen von Samba sind eigentlich recht ausführlich dokumentiert. Die Einstellungen die man meist braucht sind guest ok = Yes Es ist kein Benutzerkonto auf dem Pc nötig browseable = Yes Man kann die Freigabe im Netzwerk sehen. Nach der Änderung sollte zuerst die Richtigkeit überprüft werden: testparm dann kann man die Änderungen einlesen lassen: /etc/init.d/smb reload ==== Domänencontroller einrichten ==== * [[http://www.tecchannel.de/server/linux/1744753/|Samba als Windows Domain Controller auf dem NSLU2]] ==== Freigabe einrichten ohne Benutzer ==== Den einfachsten Fall (eine Verbindung auf Freigabe-ebene und ohne Passwortabfrage für jeden beschreibbar): [public] path = /home/user/public read only = No guest ok = Yes ''guest ok = Yes'' ist gleichbedeutend mit ''public = Yes'' ==== Freigabe einrichten mit Benutzern ==== Vorbereitung: * Systembenutzer anlegen (adduser TOM)und z.B. in Gruppe "users" stecken (usermod -g users TOM) * Ordner anlegen und entsprechende Rechter erteilen [dateiserver] comment = unser Dateiserver read only = no path = /path_to_our_files guest ok = no create mask = 0640 directory mask = 0770 * Benutzer hinzufügen: smbpasswd -a TOM * Passwort ändern: ssmbpasswd TOM * existierende Benutzer auflisten: pdbedit -w -L ==== Firewalling ==== Samba (bzw. netbios und CIFS) sollten nicht frei aus dem Internet erreichbar sein. [[https://www.stefanux.de/wiki/doku.php/linux/iptables#iptables-regeln-dauerhaft-sichern|Iptables-Regeln dauerhaft]]: In diesem Beispiel wird netbios und CIFS auf allen Interfaces AUSSER $IP blockiert (deswegen die Negation "!"). ''/etc/iptables/rules.v4'': # Generated by iptables-save *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT ! -d $IP/32 -p tcp -m tcp --dport 137:139 -j DROP -A INPUT ! -d $IP/32 -p udp -m udp --dport 137:139 -j DROP -A INPUT ! -d $IP/32 -p udp -m udp --dport 445 -j DROP -A INPUT ! -d $IP/32 -p tcp -m tcp --dport 445 -j DROP COMMIT Hier wird CIFS auf IPv6 gar nicht angeboten: ''/etc/iptables/rules.v6'' *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -p tcp -m tcp --dport 137:139 -j DROP -A INPUT -p udp -m udp --dport 137:139 -j DROP -A INPUT -p udp -m udp --dport 445 -j DROP -A INPUT -p tcp -m tcp --dport 445 -j DROP COMMIT ==== Samba an AD authentifizieren ==== * [[https://help.ubuntu.com/community/ActiveDirectoryWinbindHowto|ActiveDirectoryWinbindHowto]] * [[http://forum.ubuntuusers.de/topic/49746/|Einer Domain beitreten]] * [[http://www.pro-linux.de/work/server/samba3-domaene.html|Beitritt zu einer Windows 2003-Domäne mit Benutzerübernahme]] ==== Schattenkopien mit ZFS ==== [global] shadow: snapdir = .zfs/snapshot shadow: sort = desc # Specify snapshot name: frequent, hourly, daily… as desired shadow: format = zfs-auto-snap_hourly-%Y-%m-%d-%H%M" * https://www.samba.org/samba/docs/current/man-html/vfs_shadow_copy2.8.html * help.univention.com/t/ucs-samba-with-zfs-via-nfs-working/6865 ==== Verschlüsselung erzwingen ==== [global] min protocol = SMB2 client max protocol = SMB3 encrypt passwords = yes server signing = mandatory smb encrypt = mandatory ''testparm -v | grep protocol'' client max protocol = SMB3 client min protocol = CORE server max protocol = SMB3 server min protocol = SMB2 ==== WINS-Unterstützung ==== Samba als WINS-Server: [global] wins support = yes name resolve order = wins lmhosts hosts bcast Samba als WINS-Client: [global] wins server = IP_or_DNS-Name * [[http://lug.krems.cc/docu/samba/ch07_03.html|Kapitel 7.3 Namensauflösung unter Samba]] * [[http://www.oucs.ox.ac.uk/network/wins/client-config/index.xml.ID=body.1_div.2|2.7. Configuring a Samba Server to use WINS]] ===== Samba als standalone Dateiserver ===== Komplexes Beispiel: useradd meinUser passwd meinUser smbpasswd -a meinUser # anzeigen lassen zur Kontrolle: # pdbedit -w -L ''/etc/samba/smb.conf'' # Global parameters [global] log file = /var/log/samba/log.%m logging = file map to guest = Bad User max log size = 1000 obey pam restrictions = Yes pam password change = Yes panic action = /usr/share/samba/panic-action %d passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* . passwd program = /usr/bin/passwd %u server role = standalone server unix password sync = Yes usershare allow guests = Yes idmap config * : backend = tdb store dos attributes = no ea support = no map archive = no map hidden = no map system = no map readonly = no min protocol = SMB2 client max protocol = SMB3 encrypt passwords = yes # win7 unterstützt die folgenden beiden Einstellungen nicht: # server signing = mandatory # smb encrypt = mandatory #[homes] # browseable = No # comment = Home Directories # create mask = 0700 # directory mask = 0700 # valid users = %S [meineFreigabe] create mask = 0700 directory mask = 0700 path = /srv/samba read only = No valid users = meinUser ''systemctl restart smbd.service '' Optional: * siehe oben firewalling * in [[linux:wireguard]] tunneln ===== Samba als DC ===== * [[https://samba.plus/|Samba+ von Sernet]] # Global parameters[global] netbios name = $Servername realm = $Domainroot server role = active directory domain controller workgroup = $Domainroot tls enabled = yes tls keyfile = tls/$domain-key.pem tls certificate = tls/$domain-crt.pem tls cafile = tls/$domain-ca.pem dns forwarder = extern1.dns.resolver.tld extern2.dns.resolver.tld kccsrv:samba_kcc = false ldap server require stron auth = no [netlogon] path = /var/lib/samba/sysvol/$domain/scripts read only = No [sysvol] path = /var/lib/samba/sysvol read only = No Zertifikate nach ''/var/lib/samba/private/tls''. SAMBA_START_MODE="ad" in /etc/default/samba oder /etc/default/sernet-samba Zeitzone muss überall gleich gesetzt werden: ''timedatectl set-timezone UTC'' ==== AD-Controller neu installieren ==== Vorbereitungen: * :!: Hostname und FQDN in Hostdatei /etc/hosts schreiben (Beispiel). * netplan und systemd-resolved deaktivieren * Apparmor deaktivieren: systemctl stop apparmor && systemctl disable apparmor Der systemd-NTP wird ersetzt weil DCs signierte Zeitstempel liefern wollen, das kann ntp mit ntpsigndsocket: systemctl disable systemd-timesyncd.service apt install ntp /etc/ntp/ntp.conf # First one is a internal IP as (in case DNS fails): server 1.2.3.4 server de.pool.ntp.org server ntp.ubuntu.com # Restrictions restrict default kod limited nomodify notrap nopeer mssntp restrict 127.0.0.1 restrict ::1 restrict time.neofonie.de mask 255.255.255.255 nomodify notrap nopeer noquery # Location of drift filedriftfile /var/lib/ntp/ntpd.drift # Location of the update directory ntpsigndsocket /var/lib/samba/ntp_signd/ testen: ''ntpq> pe'' Hostname setzen: hostnamectl set-hostname $Hostname Falls cloud-init installiert ist: /etc/cloud/cloud.cfg von: "preserve_hostname: false" auf "preserve_hostname: true". Pakete deinstallieren: apt remove cloud-init cloud-initramfs-copymods cloud-initramfs-dyn-netconf **Kerberos-Config ins System**: * krb5.conf kopieren (nach erstmaligem start von samba): cp /var/lib/samba/private/krb5.conf /etc/ **Replikation beobachten**: ''samba-tool drs showrepl | less'' **Test/re-index lokale DB** (funktioniert direkt auf der DB, Samba muss nicht gestarten werden): samba-tool user list && samba-tool group list === csync2 für sysvol-Replikation === apt install csync2 xinetd konfigurieren: apt purge openbsd-inetd apt install xinetd systemctl is-enabled xinetd systemctl restart xinetd Schlüssel generieren: csync2 -k /etc/csync2.key openssl genrsa -out /etc/csync2_ssl_key.pem 2048 openssl req -batch -new -key /etc/csync2_ssl_key.pem -out /etc/csync2_ssl_cert.csr openssl x509 -req -days 9999 -in /etc/csync2_ssl_cert.csr -signkey /etc/csync2_ssl_key.pem -out /etc/csync2_ssl_cert.pem config-Dateien auf die anderen PDCs kopieren incl. keys: scp csync2* $Server2:/etc/ scp csync2* $Server3:/etc/ /etc/csync2.cfg: ignore uid; ignore gid; ignore mod; group samba4 { host $server; host $server2; host $server3; key /etc/csync2.key; include /var/lib/samba/sysvol/; exclude .*; action { exec "samba-tool ntacl sysvolreset"; } } testen: csync2 -xv Auf allen Beteiligten Nodes in den Crontabs den sync setzen (Minuten variieren damit nicht alle drei Nodes zur gleichen Sekunden syncen): */10 * * * * root csync2 -x Neuen PDC in die Domain joinen: ''samba-tool domain join $Domainame DC -U administrator'' weitere Links: * http://www.wir1234.de/wiki/doku.php?id=csync2 * https://icicimov.github.io/blog/devops/File-system-sync-with-Csync2-and-Lsyncd/ ==== Diagnose ==== * Log-Dateien: /var/log/samba/... * **Replikation** checken: ''samba-tool drs showrepl'' * Datenbankeinträge checken: ''samba-tool dbcheck --cross-ncs'' * Offene Verbindungen von Clients anzeigen: ''smbstatus'' **Bind**: * Cache des Bind ggf. löschen: ''rndc flush'' * Cache anzeigen: ''rndc dumpdb -all'' **NTP-Daemon prüfen**: ''ntpq -p'' * AD-Informationen anzeigen: ''net ads info'' * Informationen über DCs anzeigen: ''samba-tool dns serverinfo $servername -U Administrator'' * Master finden: ''samba-tool fsmo show'' * AD anpingen: ''wbinfo --ping-dc'' * User-Liste anzeigen: wbi'' * Aktuelle Benutzer-Zahl: wbinfo -u | wc -l'' * Liste der Gruppen: ''wbinfo -g'' * Anzahl von Gruppen: ''wbinfo -g | wc -l'' * Alle Zahlen zusammen: ''net rpc info -U Administrator'' * Schnelle Verifikation von Usern auf verschiedenen PDCs: ''for x in `wbinfo -u`; do wbinfo --name-to-sid $x; done'' Bei TKEY Problemen: Rechte anpassen chgrp bind /var/lib/samba/private/ chmod 750 /var/lib/samba/private/ chgrp bind /var/lib/samba/private/dns.keytab chmod 640 /var/lib/samba/private/dns.keytab * DNS-Zoneninformationen abfragen (Samba direkt): ''samba-tool dns query @ ALL -U administrator'' * DNS-Zoneninformationen auflisten (Samba direkt): ''samba-tool dns zonelist --secondary -U administrator'' * Neuen DNS-Record setzen: ''samba-tool dns add localhost neofonie.de asp.neofonie.de A 81.17.211.122 -U (anyAD-Adminuser)'' ===== ansible ===== * [[https://stackoverflow.com/questions/44762488/non-interactive-samba-user-creation-via-ansible|Non interactive samba user creation via ansible]] * https://github.com/stefanux/ansible-role-samba