Docs/Security/Samba.md
2026-03-19 17:43:46 +05:00

209 lines
4.0 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 🔒 Samba Security Hardening
📚 **Полная документация по безопасной настройке Samba в домашней инфраструктуре**
---
## 📑 Содержание
- [🎯 Цели](#-цели)
- [📂 Шары](#-шары)
- [📁 Права файловой системы](#-права-файловой-системы)
- [🖥️ Клиенты](#-клиенты)
- [✅ Проверка](#-проверка)
- [🔄 Откат](#-откат)
- [📊 Статистика](#-статистика)
- [📞 Контакты](#-контакты)
---
## 🎯 Цели
- 🔐 Убрать гостевой доступ
- 👤 Ввести авторизацию пользователей
- 📁 Настроить права Linux
- 💻 Обеспечить работу Windows + Docker (qBittorrent)
---
## 📂 Шары
### 📺 Media сервер (`192.168.1.203`)
```ini
[Films]
comment = Films Library
path = /mnt/video/films
browseable = yes
read only = yes
valid users = @mediaread
write list = zailon qb
force group = mediaread
create mask = 0644
directory mask = 0755
```
---
### 🎮 Games сервер (`192.168.1.207`)
```ini
[Games]
comment = Games Library
path = /mnt/games/
browseable = yes
read only = yes
valid users = @mediaread
write list = zailon qb
force group = mediaread
create mask = 0644
directory mask = 0755
```
---
## 📁 Права файловой системы
### Media
```bash
# Владелец и группа
sudo chown -R zailon:mediaread /mnt/video/ /mnt/audio/ /mnt/books/ /mnt/abooks/
# Папки
sudo find /mnt/video/ /mnt/audio/ /mnt/books/ /mnt/abooks/ -type d -exec chmod 775 {} \;
# Файлы
sudo find /mnt/video/ /mnt/audio/ /mnt/books/ /mnt/abooks/ -type f -exec chmod 664 {} \;
```
### Games
```bash
sudo chown -R zailon:mediaread /mnt/games/
sudo find /mnt/games/ -type d -exec chmod 775 {} \;
sudo find /mnt/games/ -type f -exec chmod 664 {} \;
```
---
## 🖥️ Клиенты
### 🧲 Torrent (`192.168.1.211`)
```bash
sudo mkdir -p /etc/smb-creds
sudo nano /etc/smb-creds/qb
sudo chmod 600 /etc/smb-creds/qb
```
#### `/etc/fstab`
```ini
//192.168.1.203/Films /mnt/video/films cifs rw,credentials=/etc/smb-creds/qb,uid=1000,gid=1003,file_mode=0644,dir_mode=0755,vers=3.0 0 0
//192.168.1.207/Games /mnt/games cifs rw,credentials=/etc/smb-creds/qb,uid=1000,gid=1003,file_mode=0644,dir_mode=0755,vers=3.0 0 0
```
Применение:
```bash
sudo mount -a
```
---
### 🪟 Windows
```cmd
net use \\\\192.168.1.203\\Films /user:zailon
net use \\\\192.168.1.207\\Games /user:zailon
```
Очистка:
```cmd
net use * /delete /yes
net stop workstation /y
net start workstation
```
---
## ✅ Проверка
### Серверы
```bash
pdbedit -L
testparm
getent group mediaread
```
### Torrent
```bash
mount | grep cifs
cat /etc/smb-creds/qb
```
### Docker test
```bash
docker exec qbittorrent touch /mnt/video/films/test.txt
docker exec qbittorrent rm /mnt/video/films/test.txt
```
---
## 🔄 Откат
⚠️ **Не рекомендуется**
```ini
guest ok = yes
```
```bash
sudo systemctl restart smbd nmbd
```
---
## 📊 Статистика
| Параметр | Значение |
|----------|----------|
| Серверов | 2 |
| Шаров | 13 |
| Пользователей | 3 |
| Групп | 1 (`mediaread`) |
| Гостевой доступ | ❌ |
---
## 📞 Контакты
| Параметр | Значение |
|----------|----------|
| Домен | zailon.ru |
| Сеть | 192.168.1.0/24 |
| VPN | 192.168.45.0/24 |
| Media | 192.168.1.203 |
| Games | 192.168.1.207 |
| Torrent | 192.168.1.211 |
---
## 🎉 Результат
✅ Гостевой доступ отключён
✅ Доступ только по пользователям
✅ Права корректны
✅ Docker пишет в шару
✅ Windows подключается
---
> 💡 README оптимизирован под GitHub: есть якоря, навигация и чистая структура