Samba server

  1. Установка

    apt update

    apt install -y samba

  2. iptables

    iptables -I INPUT -p tcp --dport 445 -j ACCEPT

    iptables -I INPUT -p udp --dport 137:138 -j ACCEPT

    iptables -I INPUT -p tcp --dport 139 -j ACCEPT

  3. public access

    nano /etc/samba/smb.conf

    [global]
    workgroup = WORKGROUP
    security = user
    map to guest = bad user
    wins support = no
    dns proxy = no
    
    [public]
    path = /samba/public
    guest ok = yes
    force user = root
    browsable = yes
    writable = yes
    
  4. Ограничить доступ по IP
    [global]
    workgroup = WORKGROUP
    security = user
    map to guest = bad user
    wins support = no
    dns proxy = no
    
    [1c_backup]
    path = /mnt/1c/backup_1c
    guest ok = yes
    force user = nobody
    #force user = root
    browsable = yes
    writable = yes
    create mask = 0777
    directory mask = 0777
    hosts allow = 192.168.18.103
    hosts deny = ALL
    
    
  5. private access
    [private]
    path = /samba/private/
    valid users = dmitry
    guest ok = no
    browsable = yes
    writable = yes
    

SMB client

Установить пакет

apt install cifs-utils -y

Создать файл с credentials

vi /etc/credentials

username=user_smb
password=S#m#B#2017
domain=corp.unac

Доступ должен быть не только по сети но ки к файловой системе!

Монтирование сетевого ресурса, используя systemd

nano /etc/systemd/system/mnt-remote.mount

[Unit]
Description=Mount SMB Share
Requires=network-online.target
After=network-online.target

[Mount]
What=//server/share
Where=/mnt/remote
Type=cifs
Options=username=your_username,password=your_password,uid=1000,gid=1000,iocharset=utf8,file_mode=0777,dir_mode=0777

[Install]
WantedBy=multi-user.target

Для монтирования SMB ресурса в режиме "только чтение" вы можете добавить параметр ro (read-only) в опции монтирования.

Options=username=your_username,password=your_password,ro

Запускаем службу

systemctl daemon-reload

systemctl start mnt-remote.mount

systemctl enable mnt-remote.mount


Монтирование сетевого ресурса - mount

Пример монтирования \\192.168.18.103\1c_backup в /mnt/mount-point
IP=192.168.18.103
SHARA_FROM=1c_backup         # Shara
MNT_POINT=/mnt/mount-point   # Точка мониторвания
SMB_V=2.0                    # Версия smb источника

mount -t cifs //$IP/$SHARA_FROM $MNT_POINT -o credentials=/etc/credentials -o vers=$SMB_V -o ro

Размонтировать

umount /mnt/mount-point

Автомонтироввание

nano /etc/fstab

//192.168.18.33/FOR_lacal/ /mnt/1c/ cifs ro,vers=3.0,user=backup_users,password=hs47s 0 0

Проверить

systemctl daemon-reload

mount -a