Samba – шары с простым парольным доступом

1. Установка

# yum install -y samba samba-client cifs-utils vim mc

2. Создание пользователей и группы в системе

# for i in user1 user2 user3; do useradd -M -s /sbin/nologin $i; done
# groupadd sambagroup
# for i in user1 user2 user3; do usermod -aG sambagroup $i; done

3. Создание директорий для шар и расстановка привилегий

# mkdir -p /home/sambashare
# chgrp sambagroup /home/sambashare
# chmod 2775 /home/sambashare
# chmod g+w /home/sambashare

4. Настройка smb.conf и добавление пользователей samba

# cd /etc/samba/
# cp smb.conf.example smb.conf
# vim smb.conf

[global]
   workgroup = WORKGROUP
   server string = Samba Server Version %v
   netbios name = SDATA

   interfaces = lo enp64s0
   hosts allow = 127. 10.8.0. 192.168.113. 10.0.0.

   # Для Аутентификации WinXP
   #ntlm auth = yes

   log file = /var/log/samba/log.%m
   # maximum size of 50KB per log file, then rotate:
   max log size = 50

   security = user
   passdb backend = tdbsam

   # Принтеры не нужны
   #load printers = yes
   #cups options = raw

#[printers]
#   comment = All Printers
#   path = /var/spool/samba
#   browseable = no
#    guest ok = no
#    writable = no
#    printable = yes

[sambashare]
    comment = Docs
    path = /home/sambashare
    write list = @sambagroup

#[ramdisk]
   #comment = RAM
   #path = /home/ramdisk
   #browseable = no
   #guest ok = no
   #write list = @sambagroup
# for i in user1 user2 user3; do smbpasswd -a $i; done

Проверим

# pdbedit -L
user1:1001:
user2:1002:
user3:1003:

5. Проверяем и стартуем

# testparm
# systemctl enable {smb,nmb}
# systemctl start {smb,nmb}
# systemctl status {smb,nmb}

6. Настройка Firewall

# firewall-cmd --get-services
# firewall-cmd --add-service=samba --permanent
# firewall-cmd --reload
# firewall-cmd --list-all

7. Выключим на время SELinux и пробуем соедениться

# getenforce
# setenforce 0

# mount -o username=user1 //localhost/sambashare /mnt
Password for user1@//localhost/sambashare: *
# mount | grep sambashare
//localhost/sambashare on /mnt type cifs (rw,relatime,vers=1.0,cache=strict,username=user1,domain=,uid=0,noforceuid,gid=0,noforcegid,addr=0000:0000:0000:0000:0000:0000:0000:0001,soft,unix,posixpaths,serverino,mapposix,acl,rsize=1048576,wsize=65536,echo_interval=60,actimeo=1)
# smbstatus

Samba version 4.7.1
PID        Username Group     Machine                   Protocol Version Encryption Signing 
----------------------------------------------------------------------------------------------------------------------------------------
1749       user1    user1     ::1 (ipv6:::1:51708)      NT1              -          -

Service     pid     Machine   Connected at                     Encryption  Signing 
---------------------------------------------------------------------------------------------
IPC$       1749     ::1       Tue Oct 23 07:10:11 PM 2018 EEST -           - 
sambashare 1749     ::1       Tue Oct 23 07:10:11 PM 2018 EEST -           -

8. Настройка SELinux и установка man-ов

# man sepolicy
# yum provides */sepolicy
# yum install -y policycoreutils-devel
# man sepolicy
# man sepolicy-manpage
# sepolicy manpage -a -p /usr/share/man/man8
# mandb -c
# semanage fcontext -a -t samba_share_t "/home/sambashare(/.*)?"
# restorecon -Rv /home/sambashare/
# cd /home/sambashare/
# ls -Zd
drwxrwxr-x. root sambagroup unconfined_u:object_r:samba_share_t:s0

Включаем обратно SELinux

# setenforce 1

Для облегчения поиска и решения проблем касающихся SELinux, нужно установить пакет setroubleshoot-server:

# yum install -y setroubleshoot-server

Теперь узнать варианты решения можно по команде:

# sealert -a /var/log/audit/audit.log

и следуя подсказкам. Для ускорения поиска можно обнулить audit.log:

# cd /var/log/audit/ && sort audit.log > audit.log

При выполнении testparm вылезло предупреждение:

[root@smb home]# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)

В конце файла дописываем:

# vim /etc/security/limits.conf

## For Samba
*          -          nofile         16384
image_pdfimage_print

Leave a Reply

Your email address will not be published. Required fields are marked *