rearranged the repository structure
BIN
raspberry/asset/nas/64bit.webp
Normal file
After Width: | Height: | Size: 135 KiB |
BIN
raspberry/asset/nas/64bitsettings.webp
Normal file
After Width: | Height: | Size: 94 KiB |
BIN
raspberry/asset/nas/access.png
Normal file
After Width: | Height: | Size: 699 KiB |
BIN
raspberry/asset/nas/acl.png
Normal file
After Width: | Height: | Size: 60 KiB |
BIN
raspberry/asset/nas/connection.png
Normal file
After Width: | Height: | Size: 42 KiB |
BIN
raspberry/asset/nas/connection1.png
Normal file
After Width: | Height: | Size: 31 KiB |
BIN
raspberry/asset/nas/dashboard.png
Normal file
After Width: | Height: | Size: 100 KiB |
BIN
raspberry/asset/nas/disco.png
Normal file
After Width: | Height: | Size: 61 KiB |
BIN
raspberry/asset/nas/folder.png
Normal file
After Width: | Height: | Size: 52 KiB |
BIN
raspberry/asset/nas/formattazione.png
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
raspberry/asset/nas/installer.png
Normal file
After Width: | Height: | Size: 86 KiB |
BIN
raspberry/asset/nas/password.png
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
raspberry/asset/nas/permessi.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
raspberry/asset/nas/permessi2.png
Normal file
After Width: | Height: | Size: 42 KiB |
BIN
raspberry/asset/nas/raid1.png
Normal file
After Width: | Height: | Size: 50 KiB |
BIN
raspberry/asset/nas/raid2.png
Normal file
After Width: | Height: | Size: 47 KiB |
BIN
raspberry/asset/nas/smb.png
Normal file
After Width: | Height: | Size: 87 KiB |
BIN
raspberry/asset/nas/smb2.png
Normal file
After Width: | Height: | Size: 137 KiB |
BIN
raspberry/asset/nas/user.png
Normal file
After Width: | Height: | Size: 66 KiB |
220
raspberry/nas.md
Normal file
@@ -0,0 +1,220 @@
|
||||
# Nas casalingo
|
||||
|
||||
<style>
|
||||
.big{
|
||||
width: 60%;
|
||||
height: auto;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
Occorrente:
|
||||
|
||||
- Raspberry PI 4 2 GB di ram;
|
||||
- cavo di rete;
|
||||
- micro SDXC da 32 GB;
|
||||
- 2 HDD TOSHIBA MG07ACA14TE (14 TB l'uno)
|
||||
|
||||
```bash
|
||||
=== START OF INFORMATION SECTION ===
|
||||
Model Family: Toshiba MG07ACA... Enterprise Capacity HDD
|
||||
Device Model: TOSHIBA MG07ACA14TE
|
||||
Serial Number: X2V0A0YFF94G
|
||||
LU WWN Device Id: 5 000039 c18d3727f
|
||||
Firmware Version: 0104
|
||||
User Capacity: 14,000,519,643,136 bytes [14.0 TB]
|
||||
Sector Sizes: 512 bytes logical, 4096 bytes physical
|
||||
Rotation Rate: 7200 rpm
|
||||
Form Factor: 3.5 inches
|
||||
Device is: In smartctl database [for details use: -P show]
|
||||
ATA Version is: ACS-3 T13/2161-D revision 5
|
||||
SATA Version is: SATA 3.3, 6.0 Gb/s (current: 6.0 Gb/s)
|
||||
Local Time is: Sun Feb 19 13:47:44 2023 CET
|
||||
SMART support is: Available - device has SMART capability.
|
||||
SMART support is: Enabled
|
||||
AAM feature is: Unavailable
|
||||
APM level is: 1 (minimum power consumption with standby)
|
||||
Rd look-ahead is: Enabled
|
||||
Write cache is: Enabled
|
||||
DSN feature is: Unavailable
|
||||
ATA Security is: Disabled, NOT FROZEN [SEC1]
|
||||
Wt Cache Reorder: Enabled
|
||||
```
|
||||
|
||||
- 2 adattatori SATA-USB 3.0
|
||||
|
||||
- Case Terrapi Extreme Duo ([https://shop.inux3d.com/it/home/101-134-terrapi-xtreme-duo.html#/13-colore-arancione](https://shop.inux3d.com/it/home/101-134-terrapi-xtreme-duo.html#/13-colore-arancione))
|
||||
|
||||
Qui le istruzioni per il montaggio: [https://shop.inux3d.com/it/index.php?controller=attachment&id_attachment=25](https://shop.inux3d.com/it/index.php?controller=attachment&id_attachment=25)
|
||||
|
||||
## Installazione Raspberry Pi OS Lite
|
||||
|
||||
Scaricare ed eseguire l'installer da questo link: [https://www.raspberrypi.com/software/](https://www.raspberrypi.com/software/), tramite i seguenti comandi:
|
||||
|
||||
```bash
|
||||
cd Scaricati
|
||||
wget -c https://downloads.raspberrypi.org/imager/imager_latest_amd64.deb
|
||||
sudo apt install ./imager_latest_amd64.deb
|
||||
```
|
||||
Avviare il programma. Scegliere come OS `Raspberry Pi OS Lite (64 bit)`
|
||||
|
||||

|
||||
|
||||
selezionare la micro SD, quindi cliccare sul pulsante delle impostazioni per personalizzare il SO:
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
Una volta inserite le impostazioni desiderate, cliccare su `Salva`, poi su `Scrivi` e attendere qualche minuto. Per poter connettersi via `ssh` e chiave pubblica, seguire la guida [ssh](./SSH.md).
|
||||
|
||||
Connettere il Raspberry Pi al router tramite cavo di rete, oppure via WiFi. Inserire la micro SD all’interno del Raspberry Pi, alimentarlo e attendere qualche minuto in modo che il Raspberry Pi completi la procedura di boot.
|
||||
|
||||
Assicurarsi di raggiungere il Raspberry Pi 4:
|
||||
|
||||
```bash
|
||||
ping indirizzo_ip_raspberry -c 10
|
||||
|
||||
> ping 192.168.52.48 -c 10
|
||||
PING 192.168.52.48 (192.168.52.48) 56(84) bytes of data.
|
||||
64 bytes from 192.168.52.48: icmp_seq=1 ttl=64 time=113 ms
|
||||
64 bytes from 192.168.52.48: icmp_seq=2 ttl=64 time=62.3 ms
|
||||
64 bytes from 192.168.52.48: icmp_seq=3 ttl=64 time=124 ms
|
||||
64 bytes from 192.168.52.48: icmp_seq=4 ttl=64 time=41.7 ms
|
||||
64 bytes from 192.168.52.48: icmp_seq=5 ttl=64 time=131 ms
|
||||
64 bytes from 192.168.52.48: icmp_seq=6 ttl=64 time=161 ms
|
||||
64 bytes from 192.168.52.48: icmp_seq=7 ttl=64 time=86.2 ms
|
||||
64 bytes from 192.168.52.48: icmp_seq=8 ttl=64 time=122 ms
|
||||
64 bytes from 192.168.52.48: icmp_seq=9 ttl=64 time=63.8 ms
|
||||
64 bytes from 192.168.52.48: icmp_seq=10 ttl=64 time=136 ms
|
||||
|
||||
--- 192.168.52.48 ping statistics ---
|
||||
10 packets transmitted, 10 received, 0% packet loss, time 9004ms
|
||||
rtt min/avg/max/mdev = 41.735/104.007/160.501/36.464 ms
|
||||
```
|
||||
|
||||
Accedere ora da remoto al Raspberry Pi tramite SSH. Nel caso non si avesse generato la coppia di chiavi, ci si può sempre connettere tramite il comando:
|
||||
|
||||
```bash
|
||||
ssh host@indirizzo_ip
|
||||
|
||||
ssh pi@192.168.1.20
|
||||
```
|
||||
|
||||
## Installazione OpenMediaVault
|
||||
|
||||
Aggiornare i pacchetti, le dipendenze e il SO col comando:
|
||||
|
||||
```bash
|
||||
sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y && sudo apt full-upgrade
|
||||
```
|
||||
|
||||
Una volta completata la procedura di aggiornamento del Raspberry Pi, eseguire il seguente comando che in primo luogo scaricherà lo script di installazione di **OpenMediaVault**
|
||||
e successivamente lo eseguirà.
|
||||
Attraverso questo script verranno installati e configurati tutti i componeti necessari per eseguire **OpenMediaVault** sul Raspberry Pi:
|
||||
|
||||
```bash
|
||||
sudo wget -O - https://github.com/**OpenMediaVault**-Plugin-Developers/installScript/raw/master/install | sudo bash
|
||||
```
|
||||
|
||||
Al termine dell'installazione, la sessione SSH verrà chiusa automaticamente.
|
||||
|
||||
## Configurazione
|
||||
|
||||
Per essere in grado di accedere alla web GUI di **OpenMediaVault**, è necessario conoscere l’indirizzo IP del Raspberry Pi. Se non lo si conoscesse, è possibile eseguire il seguente comando per visualizzarlo:
|
||||
|
||||
```bash
|
||||
hostaname -I
|
||||
```
|
||||
|
||||
Con l’indirizzo IP locale del Raspberry Pi, si può accedere all'interfaccia web:
|
||||
|
||||
```bash
|
||||
http://ip-raspberrypi
|
||||
```
|
||||
|
||||
Dopo aver caricato l’interfaccia web di **OpenMediaVault**, verrà chiesto di effettuare il login per poter procedere.
|
||||
|
||||
Il nome utente predefinito è `admin` e la password predefinita è `openmediavault`.
|
||||
|
||||

|
||||
|
||||
Una delle prime cose da fare è cambiare la password del account admin di OpenMediaVault:
|
||||
|
||||

|
||||
|
||||
Dallo stesso menù è anche possibile personalizzare la `Dashboard` in modo da avere più informazioni a colpo d'occhio:
|
||||
|
||||

|
||||
|
||||
## Creazione del File System
|
||||
|
||||
Dopo aver collegato i due dischi, formattarli e ripristinarli allo stato di fabbrica:
|
||||
|
||||

|
||||
|
||||
Impostare i due dischi nel modo seguente:
|
||||
|
||||

|
||||
|
||||
### Creazione RAID 1
|
||||
|
||||

|
||||
|
||||
```bash
|
||||
Tipo: BTRFS
|
||||
Profile: RAID1
|
||||
|
||||
Selezionare i due HDD
|
||||
```
|
||||
|
||||

|
||||
|
||||
Cliccare su crea e attendere che venga creato appunto il File System.
|
||||
|
||||
## Cartelle condivise
|
||||
|
||||
### Utenti
|
||||
|
||||
Come prima cosa, creare gli utenti di OMV necessari, i quali potranno accedere alle cartelle condivise in lettura/scrittura o solo in lettura. Fondamentale che l'utente sia aggiunto al gruppo `sambashare`.
|
||||
|
||||

|
||||
|
||||
### Shared Folders
|
||||
|
||||
Creare la cartella (o le cartelle) da condividere:
|
||||
|
||||

|
||||
|
||||
Impostare i permessi di lettura/scrittura corretti:
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
### Condivisione
|
||||
|
||||
In questo modo viene condivisa la cartella precedentemente creata
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
### Testare la Condivisione
|
||||
|
||||
Da Dolphin o qualsiasi File Manager:
|
||||
|
||||

|
||||
|
||||
Accedere con l'utente amministratore o con l'utente standard, a seconda:
|
||||
|
||||

|
||||
|
||||
## Collegamenti
|
||||
|
||||
- [https://www.fargionconsulting.com/installazione-di-openmediavault-su-raspberry-pi/](https://www.fargionconsulting.com/installazione-di-openmediavault-su-raspberry-pi/)
|
||||
- [https://github.com/OpenMediaVault-Plugin-Developers/installScript](https://github.com/OpenMediaVault-Plugin-Developers/installScript)
|
||||
- [https://www.maffucci.it/2022/02/20/installare-raspberry-pi-os-senza-monitor-e-tastiera-abilitazione-server-ssh/]( https://www.maffucci.it/2022/02/20/installare-raspberry-pi-os-senza-monitor-e-tastiera-abilitazione-server-ssh/)
|
||||
- [https://www.ilsoftware.it/articoli.asp?tag=OpenMediaVault-cos-e-e-come-costruire-un-NAS-da-soli_19009](https://www.ilsoftware.it/articoli.asp?tag=OpenMediaVault-cos-e-e-come-costruire-un-NAS-da-soli_19009)
|
159
raspberry/rasp.md
Normal file
@@ -0,0 +1,159 @@
|
||||
# Configurazione Raspberry Pi da riga di comando
|
||||
|
||||
Scaricare la ISO da [https://www.raspberrypi.com/software/operating-systems/](https://www.raspberrypi.com/software/operating-systems/)
|
||||
|
||||
```bash
|
||||
cd ~/Scaricati
|
||||
wget -c https://downloads.raspberrypi.org/raspios_lite_arm64/images/raspios_lite_arm64-2023-02-22/2023-02-21-raspios-bullseye-arm64-lite.img.xz
|
||||
```
|
||||
|
||||
Quindi decomprimere l'archivio:
|
||||
|
||||
```bash
|
||||
xz -d 2023-02-21-raspios-bullseye-arm64-lite.img.xz
|
||||
```
|
||||
## Flashare il SO sulla microSD
|
||||
|
||||
Tramite il comando `lsblk -f` individuare il device corretto.
|
||||
|
||||
Quindi smontare il device. Una volta smontato procedere a:
|
||||
|
||||
- creare una nuova tabella gpt;
|
||||
- creare una nuova partizione;
|
||||
- formattare la partizione nel file-system `ext4`;
|
||||
- flashare la iso tramite `dd`:
|
||||
|
||||
```bash
|
||||
sudo lsblk -f
|
||||
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
|
||||
sda
|
||||
├─sda1 vfat FAT32 bootfs 37CA-39EC
|
||||
└─sda2 ext4 1.0 rootfs a4af13c6-d165-4cbd-a9f6-c961fef8255d 344,9M 73% /media/davide/rootfs
|
||||
|
||||
umount /dev/sda1
|
||||
umount /dev/sda2
|
||||
|
||||
sudo fdisk /dev/sda
|
||||
Comando (m per richiamare la guida): g
|
||||
Created a new GPT disklabel (GUID: CE1B9100-FFF7-0041-9C6F-34080C8A08C6).
|
||||
Comando (m per richiamare la guida): n
|
||||
Numero della partizione (1-128, default 1):
|
||||
First sector (2048-124805086, default 2048):
|
||||
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-124805086, default 124803071):
|
||||
Created a new partition 1 of type 'Linux filesystem' and of size 59,5 GiB.
|
||||
Comando (m per richiamare la guida): w
|
||||
The partition table has been altered.
|
||||
Calling ioctl() to re-read partition table.
|
||||
Syncing disks.
|
||||
|
||||
sudo mkfs.ext4 /dev/sda1
|
||||
mke2fs 1.47.0 (5-Feb-2023)
|
||||
Creating filesystem with 15600128 4k blocks and 3907584 inodes
|
||||
Filesystem UUID: ab33b6d8-fdf0-44b5-977d-3511ee17c9ed
|
||||
Superblock backups stored on blocks:
|
||||
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
|
||||
4096000, 7962624, 11239424
|
||||
|
||||
Allocating group tables: done
|
||||
Writing inode tables: done
|
||||
Creating journal (65536 blocks): done
|
||||
Writing superblocks and filesystem accounting information: done
|
||||
|
||||
umount /dev/sda1
|
||||
|
||||
dd if=2023-02-21-raspios-bullseye-arm64-lite.img of=/dev/sda status=progress
|
||||
|
||||
sudo lsblk
|
||||
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
|
||||
sda 8:0 1 59,5G 0 disk
|
||||
├─sda1 8:1 1 256M 0 part /media/davide/bootfs
|
||||
└─sda2 8:2 1 1,7G 0 part /media/davide/rootfs
|
||||
```
|
||||
In questo modo si otterranno le due partizioni seguenti:
|
||||
|
||||
```bash
|
||||
sudo lsblk -f
|
||||
|
||||
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
|
||||
sda
|
||||
├─sda1 vfat FAT32 bootfs 37CA-39EC 224,4M 12% /media/davide/bootfs
|
||||
└─sda2 ext4 1.0 rootfs a4af13c6-d165-4cbd-a9f6-c961fef8255d 344,9M 73% /media/davide/rootfs
|
||||
```
|
||||
|
||||
## Configurazione della rete wireless
|
||||
|
||||
```bash
|
||||
cd /media/davide/bootfs/
|
||||
|
||||
cat wpa_supplicant.conf
|
||||
|
||||
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
|
||||
country=IT
|
||||
update_config=1
|
||||
|
||||
network={
|
||||
ssid="<name>"
|
||||
psk="***********"
|
||||
}
|
||||
```
|
||||
|
||||
## Configurazione utente
|
||||
|
||||
```bash
|
||||
cat userconf.txt
|
||||
|
||||
davide:$6$Nf4LCWz7u2fcO4Vs$Z2S/T6IjgLXWTAWZfmWUbnraE0haKD0O7tt43ytGC3O7sN14UDOOGeZ7RDHOUxUZlqOOq54Ry2eAVcNfnRbiX.
|
||||
```
|
||||
Per generare la password crittografata dare il comando:
|
||||
|
||||
```bash
|
||||
openssl passwd -6
|
||||
```
|
||||
|
||||
## Configurazione ssh
|
||||
|
||||
Creare in `bootfs` il file `.sh` e appendere `net.ifnames=0` nel file `cmdline.txt`
|
||||
|
||||
```bash
|
||||
cat cmdline.txt
|
||||
|
||||
console=serial0,115200 console=tty1 root=PARTUUID=e088fd39-02 rootfstype=ext4 fsck.repair=yes rootwait quiet init=/usr/lib/raspberrypi-sys-mods/firstboot net.ifnames=0
|
||||
```
|
||||
## Impostare indirizzo IP statico
|
||||
|
||||
```bash
|
||||
cd /media/davide/rootfs/
|
||||
cd etc/
|
||||
tail -n 5 dhcpcd.conf
|
||||
|
||||
interface wlan0
|
||||
static ip_address=192.168.1.100/24
|
||||
static routers=192.168.1.1
|
||||
static domain_name_servers=5.2.75.75
|
||||
```
|
||||
|
||||
## Cambiare hostname
|
||||
|
||||
Nella medesima directory, modificare il nome host nei due seguenti file:
|
||||
|
||||
```bash
|
||||
cat hostname
|
||||
|
||||
pi
|
||||
|
||||
cat hosts
|
||||
|
||||
127.0.0.1 localhost
|
||||
::1 localhost ip6-localhost ip6-loopback
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
|
||||
127.0.1.1 pi
|
||||
```
|
||||
|
||||
## Collegamenti
|
||||
|
||||
- [https://www.raspberrypi.com/software/operating-systems/j](https://www.raspberrypi.com/software/operating-systems/j)
|
||||
- [https://www.raspberrypi.com/documentation/computers/configuration.html#setting-up-a-headless-raspberry-pi](https://www.raspberrypi.com/documentation/computers/configuration.html#setting-up-a-headless-raspberry-pi)
|
||||
- [https://learn.sparkfun.com/tutorials/headless-raspberry-pi-setup/ethernet-with-static-ip-address](https://learn.sparkfun.com/tutorials/headless-raspberry-pi-setup/ethernet-with-static-ip-address)
|
||||
- [https://thepihut.com/blogs/raspberry-pi-tutorials/19668676-renaming-your-raspberry-pi-the-hostname](https://thepihut.com/blogs/raspberry-pi-tutorials/19668676-renaming-your-raspberry-pi-the-hostname)
|
184
raspberry/samba.md
Normal file
@@ -0,0 +1,184 @@
|
||||
# samba
|
||||
|
||||
Esistono diversi protocolli per la condivisione di files, ma se nella rete si trovano sia computer con GNU/Linux che con Microsoft Windows,
|
||||
allora è quasi inevitabile che la scelta debba ricadere su SMB/CIFS.
|
||||
|
||||
samba è una suite di strumenti utilizzati per la condivisione tra reti miste Windows-GNU/Linux, implementando proprio il protocollo di rete `SMB/CIFS`.
|
||||
|
||||
## Installazione
|
||||
|
||||
```bash
|
||||
apt install samba samba-common smb4k
|
||||
```
|
||||
## Creazione directory
|
||||
|
||||
Prima di andare a configurare samba occorre creare le shares, ovvero le directory da condividere.
|
||||
|
||||
In questo esempio verrà creata una directory share dentro `/srv`, come indicato dal Filesystem Hierarchy Standard (FHS):
|
||||
|
||||
```bash
|
||||
sudo mkdir -p /srv/samba
|
||||
|
||||
sudo mkdir /srv/samba/pubblici
|
||||
sudo mkdir /srv/samba/files_privati
|
||||
```
|
||||
Vedremo successivamente quali permessi impostare a queste directory.
|
||||
|
||||
## Configurazione
|
||||
|
||||
Tutti i parametri di configurazione di samba si trovano in `/etc/samba/smb.conf`.
|
||||
|
||||
Ogni volta che si apportano delle modifiche al file sopra citato è necessario riavviare il servizio di samba:
|
||||
|
||||
```bash
|
||||
sudo systemctl restart smbd.service
|
||||
sudo systemctl restart nmbd.service
|
||||
```
|
||||
|
||||
### Sezione global
|
||||
|
||||
La sezione `[global]` si trova sempre all'inizio della configurazione del file `/etc/samba/smb.conf`.
|
||||
|
||||
Definisce le impostazioni del server samba e le opzioni di default che verranno assegnate alle condivisioni. I principali parametri del server:
|
||||
|
||||
```bash
|
||||
[global]
|
||||
allow hosts = 192.168.1.0/24 # Range di IP che possono accedere al server
|
||||
workgroup = WORKGROUP # Nome del gruppo di lavoro
|
||||
security = USER # Livello di sicurezza delle condivisioni
|
||||
server string = FILE SERVER # Descrizione della macchina
|
||||
create mask = 755 # Permessi sulle cartelle
|
||||
```
|
||||
Nel parametro `security` si poteva utilizzare in alternativa il valore `SHARE` in modo da creare condivisioni liberamente accessibili, senza necessità di autenticazioni.
|
||||
|
||||
Altri possibili valori sono:
|
||||
|
||||
- `user`: richiede utente e password per l'accesso alla condivisione;
|
||||
- `domain`: questo valore va assegnato quando si vuole configurare il server samba come Domain Controller;
|
||||
- `ADS`: questo valore consente al server samba di agganciarsi a un dominio Active Directory
|
||||
|
||||
Se si volesse rendere accessibili delle condivisioni anche ad utenti senza credenziali, inserire anche questi due parametri:
|
||||
|
||||
```bash
|
||||
map to guest = Bad User
|
||||
guest account = nobody
|
||||
```
|
||||
|
||||
### Sezione condivisione
|
||||
|
||||
Aggiungere la cartella nel file di configurazione `/etc/samba/smb.conf`:
|
||||
|
||||
```bash
|
||||
[shared]
|
||||
comment = Cartella condivisa # Commento sulla condivisione
|
||||
path = /cartella/da/condividere # Percorso della condivisione
|
||||
browseable = yes # Rende visibile la condivisione
|
||||
public = yes # Rende la cartella accessibile
|
||||
create mask = 0755 # Permessi dei file
|
||||
```
|
||||
|
||||
Dove /cartella/da/condividere è la directory da condividere.
|
||||
|
||||
#### Esempio di condivisione pubblica
|
||||
|
||||
Ecco alcuni esempi di condivisioni, ciascuno con una politica di sicurezza differente. Sotto alla sezione global scrivere:
|
||||
|
||||
```bash
|
||||
[pubblici]
|
||||
comment = files pubblici
|
||||
path = /srv/samba/pubblici
|
||||
writeable = yes
|
||||
browsable = yes
|
||||
guest ok = yes
|
||||
read only = no
|
||||
create mask = 770
|
||||
```
|
||||
|
||||
A questa condivisione avrà accesso qualsiasi utente di sistema.
|
||||
|
||||
Se in [global] è presente l'opzione `map to guest = Bad User` non verrà richiesta alcuna password e l'utente che verrà utilizzato è quello indicato in guest account (nobody).
|
||||
|
||||
In caso contrario verranno chieste le credenziali, ma qualsiasi utente di sistema potrà accedervi.
|
||||
|
||||
Con `create mask` vengono indicati i permessi nella classica scrittura Unix.
|
||||
|
||||
#### Esempio di condivisione privata
|
||||
|
||||
```bash
|
||||
[files_privati]
|
||||
comment = Files privati di Luca
|
||||
path = /srv/samba/files_privati
|
||||
browsable = no
|
||||
guest ok = no
|
||||
valid users = Luca
|
||||
```
|
||||
|
||||
A questa condivisione avrà accesso solamente l'utente Luca.
|
||||
|
||||
Tramite l'opzione browsable=no è impedita la visualizzazione della cartella tra le condivisioni samba. L'utente Luca per accedervi dovrà richiamarla direttamente.
|
||||
|
||||
## Montare condivisione
|
||||
|
||||
Per montare una condivisone samba presente su un altro file server, si utilizza il seguente comando:
|
||||
|
||||
```bash
|
||||
smbmount //SERVER/condivisione /punto/di/mount
|
||||
```
|
||||
|
||||
Dove `/punto/di/mount/` è una directory creata con privilegi di amministrazione solitamente in `/media`.
|
||||
|
||||
## Connessione al server
|
||||
|
||||
Per connettersi ad un server samba si usa:
|
||||
|
||||
```bash
|
||||
smbclient //SERVER/condivisione
|
||||
```
|
||||
### Sicurezza e controllo accessi
|
||||
|
||||
L'accesso alle directory condivise viene regolato sia nativamente a livello di file system, sia a livello di condivisione samba.
|
||||
|
||||
#### Aggiungere utente
|
||||
|
||||
Per quanto riguarda la condivisione `[files_privati]`, solo l'utente Luca può accedervi e scrivere al suo interno.
|
||||
Perché questo funzioni però bisogna creare l'utente Luca su samba e assegnargli, sul server, la directory interessata.
|
||||
|
||||
Prima di aggiunge un utente su samba bisogna che questo sia presente nel sistema.
|
||||
|
||||
```bash
|
||||
sudo adduser luca --home=/home/public --shell=/bin/false --disabled-password
|
||||
```
|
||||
|
||||
L’opzione `--shell=/bin/false disabilita` l’accesso alla shell da parte dell’utente creato, che non avrà quindi possibilità di fare un vero e proprio login. Questo per ragioni di sicurezza, come accade per gli account di sistema.
|
||||
|
||||
Creare quindi l'utente in samba:
|
||||
|
||||
```bash
|
||||
sudo smbpasswd -a Luca
|
||||
```
|
||||
|
||||
Creato l'utente bisogna ora assegnargli la directory alla quale dovrà accedere:
|
||||
|
||||
```bash
|
||||
sudo chown luca files_privati
|
||||
sudo chmod -R 700 /srv/samba/files_privati
|
||||
```
|
||||
|
||||
In qualsiasi momento è possibile vedere la lista degli utenti samba con relative informazioni tramite il comando:
|
||||
|
||||
```bash
|
||||
sudo pdbedit -L -v
|
||||
```
|
||||
dove -L richiede l'elenco degli utenti, l'opzione -v, invece, sta per `verbose`.
|
||||
|
||||
## Log di samba
|
||||
|
||||
Tutti i log di samba sono presenti nella cartella `/var/log/samba`.
|
||||
|
||||
## Collegamenti
|
||||
|
||||
- [https://wiki.ubuntu-it.org/Server/samba](https://wiki.ubuntu-it.org/Server/samba)
|
||||
- [https://www.mrw.it/linux/creiamo-file-server-samba_7411.html](https://www.mrw.it/linux/creiamo-file-server-samba_7411.html)
|
||||
- [https://guide.debianizzati.org/index.php/Installare_Samba_per_condividere_directory_-_Debian_Stretch](https://guide.debianizzati.org/index.php/Installare_Samba_per_condividere_directory_-_Debian_Stretch)
|
||||
- [https://guide.debianizzati.org/index.php/Samba:_guida_rapida](https://guide.debianizzati.org/index.php/Samba:_guida_rapida)
|
||||
|
408
raspberry/sambashare.md
Normal file
@@ -0,0 +1,408 @@
|
||||
# Nas con samba
|
||||
|
||||
## Impostare IP statico
|
||||
|
||||
Collegarsi al raspberry via ssh, quindi modificare il seguente file, aggiungendo le righe sottostanti:
|
||||
|
||||
```bash
|
||||
nano /etc/dhcpcd.conf
|
||||
|
||||
interface wlan0
|
||||
static ip_address=192.168.1.107/24
|
||||
static routers=192.168.1.1
|
||||
static domain_name_servers=192.168.1.1 5.2.75.75
|
||||
```
|
||||
|
||||
## Identificare e partizionare i dischi
|
||||
|
||||
```bash
|
||||
fdisk -l
|
||||
|
||||
Disk /dev/sda: 12.73 TiB, 14000519643136 bytes, 27344764928 sectors
|
||||
Disk model: Generic
|
||||
Units: sectors of 1 * 512 = 512 bytes
|
||||
Sector size (logical/physical): 512 bytes / 4096 bytes
|
||||
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
|
||||
Disklabel type: gpt
|
||||
Disk identifier: 4AE9456D-B7BA-4011-87ED-A73741BAA769
|
||||
|
||||
Device Start End Sectors Size Type
|
||||
/dev/sda1 2048 27344764894 27344762847 12.7T Linux filesystem
|
||||
|
||||
|
||||
Disk /dev/sdb: 12.73 TiB, 14000519643136 bytes, 27344764928 sectors
|
||||
Disk model: Generic
|
||||
Units: sectors of 1 * 512 = 512 bytes
|
||||
Sector size (logical/physical): 512 bytes / 4096 bytes
|
||||
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
|
||||
Disklabel type: gpt
|
||||
Disk identifier: 1499002A-74AD-446F-994F-F07DF88B7E16
|
||||
```
|
||||
È possibile identificare i dischi anche con altri comandi:
|
||||
|
||||
```bash
|
||||
lsblk -f
|
||||
|
||||
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINT
|
||||
sda
|
||||
sdb
|
||||
mmcblk0
|
||||
|-mmcblk0p1 vfat FAT32 bootfs 37CA-39EC 224.3M 12% /boot
|
||||
`-mmcblk0p2 ext4 1.0 rootfs a4af13c6-d165-4cbd-a9f6-c961fef8255d 54.4G 3% /
|
||||
|
||||
blkid
|
||||
|
||||
/dev/mmcblk0p1: LABEL_FATBOOT="bootfs" LABEL="bootfs" UUID="37CA-39EC" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="be140fba-01"
|
||||
/dev/mmcblk0p2: LABEL="rootfs" UUID="a4af13c6-d165-4cbd-a9f6-c961fef8255d" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="be140fba-02"
|
||||
/dev/sda: PTUUID="4ae9456d-b7ba-4011-87ed-a73741baa769" PTTYPE="gpt"
|
||||
/dev/sdb: PTUUID="1499002a-74ad-446f-994f-f07df88b7e16" PTTYPE="gpt"
|
||||
```
|
||||
### Partizionare i dischi
|
||||
|
||||
```bash
|
||||
fdisk /dev/sda
|
||||
|
||||
Welcome to fdisk (util-linux 2.36.1).
|
||||
|
||||
Command (m for help): m
|
||||
|
||||
Help:
|
||||
|
||||
GPT
|
||||
M enter protective/hybrid MBR
|
||||
|
||||
Generic
|
||||
d delete a partition
|
||||
F list free unpartitioned space
|
||||
l list known partition types
|
||||
n add a new partition
|
||||
p print the partition table
|
||||
t change a partition type
|
||||
v verify the partition table
|
||||
i print information about a partition
|
||||
|
||||
Misc
|
||||
m print this menu
|
||||
x extra functionality (experts only)
|
||||
|
||||
Script
|
||||
I load disk layout from sfdisk script file
|
||||
O dump disk layout to sfdisk script file
|
||||
|
||||
Save & Exit
|
||||
w write table to disk and exit
|
||||
q quit without saving changes
|
||||
|
||||
Create a new label
|
||||
g create a new empty GPT partition table
|
||||
G create a new empty SGI (IRIX) partition table
|
||||
o create a new empty DOS partition table
|
||||
s create a new empty Sun partition table
|
||||
|
||||
|
||||
Command (m for help): g
|
||||
Created a new GPT disklabel (GUID: 4D12D92A-E17B-114E-8805-762CC6E5A690).
|
||||
|
||||
Command (m for help): n
|
||||
Partition number (1-128, default 1): 1
|
||||
First sector (2048-27344764894, default 2048):
|
||||
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-27344764894, default 27344764894):
|
||||
|
||||
Created a new partition 1 of type 'Linux filesystem' and of size 12.7 TiB.
|
||||
|
||||
Command (m for help): w
|
||||
The partition table has been altered.
|
||||
Calling ioctl() to re-read partition table.
|
||||
Syncing disks.
|
||||
|
||||
```
|
||||
Dopo aver partizionato anche `/dev/sdb`:
|
||||
|
||||
```bash
|
||||
lsblk -f
|
||||
|
||||
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINT
|
||||
sda
|
||||
`-sda1
|
||||
sdb
|
||||
`-sdb1
|
||||
mmcblk0
|
||||
|-mmcblk0p1 vfat FAT32 bootfs 37CA-39EC 224.3M 12% /boot
|
||||
`-mmcblk0p2 ext4 1.0 rootfs a4af13c6-d165-4cbd-a9f6-c961fef8255d 54.4G 3% /
|
||||
```
|
||||
|
||||
## Formattare il disco
|
||||
|
||||
Assicurarsi che entrambi i dispositivi siano smontati:
|
||||
|
||||
```bash
|
||||
umount /dev/sda
|
||||
umount: /dev/sda: not mounted.
|
||||
|
||||
umount /dev/sdb
|
||||
umount: /dev/sdb: not mounted.
|
||||
```
|
||||
|
||||
Quindi formattarli in `ext4`:
|
||||
|
||||
```bash
|
||||
mkfs.ext4 -L "NAS1" /dev/sda1 -v
|
||||
|
||||
mke2fs 1.46.2 (28-Feb-2021)
|
||||
fs_types for mke2fs.conf resolution: 'ext4', 'big'
|
||||
Filesystem label=NAS1
|
||||
OS type: Linux
|
||||
Block size=4096 (log=2)
|
||||
Fragment size=4096 (log=2)
|
||||
Stride=0 blocks, Stripe width=0 blocks
|
||||
427261952 inodes, 3418095355 blocks
|
||||
170904767 blocks (5.00%) reserved for the super user
|
||||
First data block=0
|
||||
Maximum filesystem blocks=4294967296
|
||||
104312 block groups
|
||||
32768 blocks per group, 32768 fragments per group
|
||||
4096 inodes per group
|
||||
Filesystem UUID: 95db731d-5687-4681-bdac-b0d57dea0260
|
||||
Superblock backups stored on blocks:
|
||||
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
|
||||
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
|
||||
102400000, 214990848, 512000000, 550731776, 644972544, 1934917632,
|
||||
2560000000
|
||||
|
||||
Allocating group tables: done
|
||||
Writing inode tables: done
|
||||
Creating journal (262144 blocks): done
|
||||
Writing superblocks and filesystem accounting information: done
|
||||
```
|
||||
### Verificare la formattazione
|
||||
|
||||
```bash
|
||||
file -sL /dev/sda1
|
||||
/dev/sda1: Linux rev 1.0 ext4 filesystem data, UUID=95db731d-5687-4681-bdac-b0d57dea0260, volume name "NAS1" (extents) (64bit) (large files) (huge files)
|
||||
|
||||
file -sL /dev/sdb1
|
||||
/dev/sdb1: Linux rev 1.0 ext4 filesystem data, UUID=c2ccecd7-5ce2-4441-a134-f8d293831aea, volume name "NAS2" (extents) (64bit) (large files) (huge files)
|
||||
```
|
||||
|
||||
## fstab
|
||||
|
||||
Creare i punti di mount nella cartella `/srv/`:
|
||||
|
||||
```bash
|
||||
root@iron:/# cd /srv/
|
||||
root@iron:/srv# mkdir private/
|
||||
root@iron:/srv# mkdir public/
|
||||
```
|
||||
Procedere quindi a modificare il file fstab:
|
||||
|
||||
```bash
|
||||
root@iron:/media# cat /etc/fstab
|
||||
proc /proc proc defaults 0 0
|
||||
PARTUUID=be140fba-01 /boot vfat defaults 0 2
|
||||
PARTUUID=be140fba-02 / ext4 defaults,noatime 0 1
|
||||
|
||||
# I due dischi
|
||||
|
||||
UUID=95db731d-5687-4681-bdac-b0d57dea0260 /srv/private/ ext4 defaults 0 2
|
||||
UUID=c2ccecd7-5ce2-4441-a134-f8d293831aea /srv/public/ ext4 defaults 0 2
|
||||
```
|
||||
Se, provando a montare i dischi non vengono restituiti errori, la procedura è avvenuta correttamente e i dischi verranno montati automaticamente all'avvio:
|
||||
|
||||
```bash
|
||||
root@iron:/media# mount /srv/private/
|
||||
root@iron:/media# mount /srv/public/
|
||||
|
||||
root@iron:/media# lsblk -f
|
||||
|
||||
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINT
|
||||
sda
|
||||
`-sda1 ext4 1.0 NAS1 95db731d-5687-4681-bdac-b0d57dea0260 12T 0% /srv/private
|
||||
sdb
|
||||
`-sdb1 ext4 1.0 NAS2 c2ccecd7-5ce2-4441-a134-f8d293831aea 12T 0% /srv/public
|
||||
mmcblk0
|
||||
|-mmcblk0p1 vfat FAT32 bootfs 37CA-39EC 224.3M 12% /boot
|
||||
`-mmcblk0p2 ext4 1.0 rootfs a4af13c6-d165-4cbd-a9f6-c961fef8255d 54.4G 3% /
|
||||
|
||||
root@iron:/media# mount -t ext4
|
||||
|
||||
/dev/mmcblk0p2 on / type ext4 (rw,noatime)
|
||||
/dev/sda1 on /srv/private type ext4 (rw,relatime)
|
||||
/dev/sdb1 on /srv/public type ext4 (rw,relatime)
|
||||
```
|
||||
|
||||
## Configurazione di samba
|
||||
|
||||
Installare i seguenti paccchetti:
|
||||
|
||||
```bash
|
||||
root@iron:/media# apt install samba samba-common-bin cifs-utils
|
||||
|
||||
Reading package lists... Done
|
||||
Building dependency tree... Done
|
||||
Reading state information... Done
|
||||
cifs-utils is already the newest version (2:6.11-3.1+deb11u1).
|
||||
The following additional packages will be installed:
|
||||
attr ibverbs-providers libavahi-client3 libboost-iostreams1.74.0 libboost-thread1.74.0 libcephfs2 libcups2
|
||||
libgfapi0 libgfrpc0 libgfxdr0 libglusterfs0 libibverbs1 libldb2 librados2 librdmacm1 libtdb1 liburing1
|
||||
python3-cffi-backend python3-cryptography python3-dnspython python3-gpg python3-ldb python3-markdown
|
||||
python3-pygments python3-requests-toolbelt python3-samba python3-talloc python3-tdb python3-yaml samba-common
|
||||
samba-dsdb-modules samba-libs samba-vfs-modules tdb-tools
|
||||
Suggested packages:
|
||||
cups-common python-cryptography-doc python3-cryptography-vectors python3-sniffio python3-trio python-markdown-doc
|
||||
python-pygments-doc ttf-bitstream-vera bind9 bind9utils ctdb ldb-tools ntp | chrony smbldap-tools ufw winbind
|
||||
heimdal-clients
|
||||
The following NEW packages will be installed:
|
||||
attr ibverbs-providers libavahi-client3 libboost-iostreams1.74.0 libboost-thread1.74.0 libcephfs2 libcups2
|
||||
libgfapi0 libgfrpc0 libgfxdr0 libglusterfs0 libibverbs1 libldb2 librados2 librdmacm1 libtdb1 liburing1
|
||||
python3-cffi-backend python3-cryptography python3-dnspython python3-gpg python3-ldb python3-markdown
|
||||
python3-pygments python3-requests-toolbelt python3-samba python3-talloc python3-tdb python3-yaml samba
|
||||
samba-common samba-common-bin samba-dsdb-modules samba-libs samba-vfs-modules tdb-tools
|
||||
0 upgraded, 36 newly installed, 0 to remove and 0 not upgraded.
|
||||
Need to get 29.6 MB of archives.
|
||||
After this operation, 113 MB of additional disk space will be used.
|
||||
Do you want to continue? [Y/n]
|
||||
```
|
||||
### Global section
|
||||
|
||||
In `/etc/samba/smb.conf` aggiungere:
|
||||
|
||||
```bash
|
||||
[global]
|
||||
#allow hosts = 192.168.1.0/24
|
||||
workgroup = WORKGROUP
|
||||
security = USER
|
||||
server string = FILE SERVER
|
||||
create mask = 0755
|
||||
browsable = no
|
||||
```
|
||||
|
||||
### Share section
|
||||
|
||||
```bash
|
||||
[private]
|
||||
comment = Cartella condivisa
|
||||
path = /srv/private
|
||||
browsable = no
|
||||
read only = no
|
||||
writable = yes
|
||||
guest ok = no
|
||||
create mask = 0775
|
||||
valid users = @samba
|
||||
```
|
||||
|
||||
Verificare che la configurazione sia corretta col comando:
|
||||
|
||||
```bash
|
||||
testparm
|
||||
```
|
||||
|
||||
Quindi riavviare i servizi:
|
||||
|
||||
```bash
|
||||
systemctl restart smbd.service
|
||||
systemctl restart nmbd.service
|
||||
|
||||
# oppure
|
||||
|
||||
systemctl restart smbd nmbd
|
||||
```
|
||||
|
||||
### Aggiunta utente
|
||||
|
||||
```bash
|
||||
adduser davide --home=/home/public --shell=/bin/false --disabled-password
|
||||
|
||||
Adding user `davide' ...
|
||||
Adding new group `davide' (1001) ...
|
||||
Adding new user `davide' (1001) with group `davide' ...
|
||||
Creating home directory `/home/public' ...
|
||||
Copying files from `/etc/skel' ...
|
||||
Changing the user information for davide
|
||||
Enter the new value, or press ENTER for the default
|
||||
Full Name []:
|
||||
Room Number []:
|
||||
Work Phone []:
|
||||
Home Phone []:
|
||||
Other []:
|
||||
Is the information correct? [Y/n]
|
||||
```
|
||||
#### Assegnare una password all'utente
|
||||
|
||||
```bash
|
||||
smbpasswd -a davide
|
||||
|
||||
New SMB password:
|
||||
Retype new SMB password:
|
||||
Added user davide.
|
||||
```
|
||||
|
||||
### Aggiungere l'utente al gruppo samba
|
||||
|
||||
```bash
|
||||
usermod -aG samba utente
|
||||
```
|
||||
|
||||
#### Assegnare la cartella condivisa all'utente
|
||||
|
||||
```bash
|
||||
chown davide:samba /srv/private/
|
||||
chmod -R 770 /srv/private/
|
||||
ls -lh1 /srv/private/
|
||||
total 20K
|
||||
drwxrwx--- 2 davide davide 4.0K Mar 26 17:46 files
|
||||
```
|
||||
|
||||
## Montare automaticamente la cartella condivisa
|
||||
|
||||
Installare sul client i seguenti pacchetti:
|
||||
|
||||
```bash
|
||||
sudo apt-get install cifs-utils smb4k
|
||||
```
|
||||
|
||||
Creare nella propria home un file `.smbcredentials` coi seguenti dati:
|
||||
|
||||
```bash
|
||||
username=shareuser
|
||||
password=sharepassword
|
||||
domain=workgroupname
|
||||
```
|
||||
|
||||
Quindi `chmod 0600 ~/.smbcredentials`.
|
||||
|
||||
Modificare il file `/etc/fstab` nel seguente modo:
|
||||
|
||||
```bash
|
||||
cat /etc/fstab
|
||||
#
|
||||
# <file system> <mount point> <type> <options> <dump> <pass>
|
||||
|
||||
//192.168.1.107/private/ /media/davide/samba cifs credentials=/home/davide/.smbcredentials,uid=davide,gid=davide 0 0
|
||||
```
|
||||
|
||||
Infine dare il comando `sudo mount -a`. La cartella dovrebbe essere correttamente montata.
|
||||
|
||||
```bash
|
||||
sudo mount -a
|
||||
|
||||
mount: (hint) your fstab has been modified, but systemd still uses
|
||||
the old version; use 'systemctl daemon-reload' to reload.
|
||||
```
|
||||
|
||||
### Connettersi tramite file manager
|
||||
|
||||
Inserire nel path:
|
||||
|
||||
```bash
|
||||
smb://server/share_folder/
|
||||
|
||||
|
||||
smb://192.168.1.107/private/
|
||||
```
|
||||
|
||||
## Collegamenti
|
||||
|
||||
- [https://linuxhint.com/raspberry_pi_static_ip_setup/](https://linuxhint.com/raspberry_pi_static_ip_setup/)
|
||||
- [https://askubuntu.com/questions/157128/proper-fstab-entry-to-mount-a-samba-share-on-boot](https://askubuntu.com/questions/157128/proper-fstab-entry-to-mount-a-samba-share-on-boot)
|
||||
- [https://noviello.it/come-installare-e-configurare-samba-server-su-ubuntu-18-04-lts/](https://noviello.it/come-installare-e-configurare-samba-server-su-ubuntu-18-04-lts/)
|
||||
- [https://www.howtogeek.com/50787/add-a-user-to-a-group-or-second-group-on-linux/](https://www.howtogeek.com/50787/add-a-user-to-a-group-or-second-group-on-linux/)
|