FileServer Raspberry pi {Raspbian Jessie}

1. Introduction
If you think of a fileserver, then you're probably at a central node in a network that is accessible to all or at least should be accessible to anyone with the proper rights acquired by the administrator. Here we think especially to NAS (network attached storage), taking photos, music, films, etc ... are stored centrally located. You can view this also as a back-up your files since most of these network devices to work with multiple hard drives (rAID configurations). The Raspberry Pi could also serve well as a fileserver, especially now that the RPI has been updated to a faster CPU (https://www.raspberrypi.org/products/raspberry-pi-2-model-b/)
2. first steps
The Raspberry Pi works with the operating system Grater Bian, The tutorial specific Grater Bian Jessie. This is a stripped down version of debian. There are of course several Operating Systems for RPI, Grate Bian is the most famous.
You are going to start the RPI, Assuming that it has already groomed is to be started. The installation is not done yet, you can go here (http://computertotaal.nl/overige-elektronica/cursus-deel-1-raspberry-pi-de-ultieme-knutselcomputer-50709/pagina-3). You can always connect using putty.
2.2 Statisch IP adres
The first thing you do once logged into the RPI, it is provided with a static IP address. In the previous version of Grater Bian (Wheezy) had you under /etc/network/interfaces his. If you command cat /etc/network/interfaces performs in Jessie, This will point to /etc/dhcpcd.conf. You can also continue to use the IP that the DHCP assigned you, you want to use it then you can skip this part and go straight on to point
3. Update and upgrade.
2.2.1 What information do you need:
the following command:
Ifconfig
Is eth0 wired Internet
The data in the yellow frame you need, these may vary.
Etho0: is the permanent internet connection you will use if you want to make a fileserver.
Inet addr: 10.10.10.6 is the IP address currently obtained by DHCP from the router
Bcast: 10.10.10.255 is a broadcast, is sending a message to all work stations of a network. The message is sent to a default address, accepted by all computers. This address is in a TCP / IP network the IP-address 255.255.255.255, Here you are working on a C network so 10.10.10.255 in this case. In most cases, this will 192.168.0.255 of 192.168.1.255 his.
Mask: 255.255.255.0 is the subsnetmask. Has to do with the type of network class, A most commonly used are,B,C. You also D and E class.
Most used | first address | last address | subnet mask | number of addresses |
Klassa A | 0.0.0.0 | 127.255.255.255 | 255.0.0.0 | 16.777.214 |
class B | 128.0.0.0 | 191.255.255.255 | 255.255.0.0 | 65.524 |
class C | 192.0.0.0 | 223.255.255.255 | 255.255.255.0 | 254 |
Sudo nano /etc/dhcpcd.conf
After this command will be found in the configuration file where you go to capture the IP address. The well-stocked configuration file goes all the way down to type a few lines. The information you have just acquired using the command ifconfig.
2.2.2 Enter data
Once the bottom of the configuration file, enter the following data:
#interface eth0
iface eth0 inet static
static ip_address=10.10.10.6/24 or enter your own address here, forgets /24 not
netmask=255.255.255.0
static routers=10.10.10.1 is de default gateway: You can find the command: cat /etc/resolv.conf
static domain_name_servers=195.130.131.2 195.130.130.2 these are the DNS Telenet. You can also 8.8.8.8 8.8.4.4 use, what are the dns google.
After you have made to the data, you must restart the server with the following command:
Sudo /etc/init.d/networking restart
restart? Your server has a static IP address.
3. Update and upgrade
The upgrade of the OS (operating-system), so you can work with a completely up-to-date operating system. To do this, enter the following from commado:
sudo apt-get update
sudo apt-get upgrade
It is possible that we ask for a confirmation, You can confirm this with Y.
get with apt-get -u you see the following output:
-in, –show-upgraded Show upgraded packages; print out a list of all packages that are to be upgraded. Configuration Item: APT::Get::Show-Upgraded. |
The difference between updating and upgrading is:
Upgrade: an application is refreshed. The new version is a collection of upgrades, but it is also possible a new user interface. For example, the version number changes from version 1.0 to version 2.0. Thepdat HYPERLINK “https://nl.wikipedia.org/wiki/Update_(software)” HYPERLINK “https://nl.wikipedia.org/wiki/Update_(software)” HYPERLINK “https://nl.wikipedia.org/wiki/Update_(software)”and: an application is refreshed. Small mistakes are updated. The program is often but changed in one or a few places. For example, the version number changes 2.0 to 2.1. |
After updating and upgrading our operating system, will you install NTFS-3G.
4. NTFS-3G
This means that you can mount an NTFS formatted drive on the Linux system. Here shows how an NTFS formatted HDD on the Linux OS mount, it is not recommended in this case. This is because you are going to get in trouble later with the rights. You can skip this and proceed to step 4.2.1 ext4 mount.
Use the following command to install NTFS-3G:
Sudo apt-get install ntfs-3g
4.1.1 mount NTFS Disk (optional, you will be using EXT4)
Once the installation of the NTFS is over you can begin to mount the HDD via USB, it can mount to you /mnt (You can also choose a different place but /mnt is the most obvious).
You go to the directory /mnt by in the terminal: cd /mnt to be carried out.
Once in the directory /mnt use the command: sudo fdisk -l
Fdisk is used to create partitions, remove and / or format hard disks that are formatted using the FAT32 and other FAT file systems.
You will no doubt recognize this disk because you know what amount of GBs you want to link.
In the example below, there will be a large 2TB HDD coupled:
Fdisk -l shows U Disk /dev/sda: 1.8 TB ect.., below than / dev / sda1. sda1 is the drive coupling, of 1 after sda refers to 1 partition. To link this disc, go first under the directory /mnt Create a folder.
Next command in order to create the folder:
sudo mkdir /mnt/externaldrive
let op: no space between external and drive, otherwise you will 2 folders. If you command ls -l /mnt performs will show you that there is a map externaldrive is made.
To the hard drive to connect now to the OS, run the following command:
Sudo mount -t auto /dev/sda1 /mnt/externaldrive
To check, you can execute the following command: df -Th
Df: is used to show the disk space. Of T stands for option and is followed by displaying the file system again, h makes it human readable.
4.1.2 Ext4 mount
If you have an NTFS hard drive, and you have performed above: mount NTFS disk. format it in the following way:
Ost make sure that it is fully umounted of the filesystem: sudo umount –f /dev/sda1 /mnt/externaldrive then sudo mkfs.ext4 /dev/sda1 performing and Y select.
U zal met het commando sudo fdisk -l zien dat de partitie sda1 is, meer info bij NTFS mounten.
Nu gaat u het ext4 filesystem mounten aan het OS, sudo mount –t auto /dev/sda1 /mnt/externaldrive
4.1.3 fstab
De harde schijf is nu fysiek gekoppeld aan het systeem, wanneer u de RPI reboot zal de schijf umounted zijn. U kan dit oplossen door in het configuratiebestand fstab de mount de definiëren.
Volgend commando:
Sudo cp /etc/fstab /etc/fstab.bckp om een backup te nemen van het configuratie bestand.
Sudo nano /etc/fstab om het configuratie bestand te openen.
U plaatst het volgende onderaan het bestand: /dev/sda1 /mnt/externaldrive gevolgd door de format system ntfs of ext4. Zie afbeelding.
Ctrl o ctrl x om op te slaan en af te sluiten, systeem rebooten met sudo reboot.
5. Installeren van samba
Bij deze is de harde schijf gekoppeld aan het OS, nu kan u deze schijf nog niet bereiken via het netwerk.
Daarvoor is het netwerkprotocol samba voor nodig, met samba kan u netwerkshares aanmaken die beschikbaar kunnen zijn in o.a. Windows, Apple computers etc. U kan samba installeren met het volgende commando:
sudo apt-get install samba
Als het bovenstaande commando niet werkt gebruikt u het volgende:
Sudo apt-get install samba samba-common-bin
Eens de installatie van samba gedaan is, maakt u best een back-up van het configuratiebestand smb.conf. Dit is het configuratiebestand dat gebruikt wordt om o.a. de netwerkconfiguratie, beveiliging, shares, etc… in aan te passen. Daarom is het verstandig hiervan een back-up te nemen. Doe dit voor alle configuratie bestanden die u in de toekomst zou willen aanpassen. Back-up neem je met het commando:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.backup
Fouten in het originele configuratiebestand? Ga terug naar het originele configuratiebestand met het omgekeerde commando.
sudo cp /etc/samba/smb.conf.backup /etc/samba/smb.conf
5.1 Samba verder uitwerken
Nu samba geïnstalleerd is kunnen we gebruikers en shares aanmaken. Wat wil dit concreet zeggen: u hebt gebruikers op uw RPI, standaard staat de gebruiker pi voor u geconfigureerd met het paswoord raspberry. Alleen is deze nog niet toegevoegd aan samba. Om meerdere gebruikers toe te voegen gebruikt u het commando:
Sudo useradd –m bitfix
U hebt de gebruiker bitfix aangemaakt met useradd, door de optie –m mee te geven hebt u voor de gebruiker bitfix ook een home-directoy aangemaakt. Wil u de gebruiker bitfix toevoegen aan een groep dan is dit mogelijk met het commando: sudo usermod –g mythras bitfix mythras is hier de groep. Hebt u geen groep dan kan u er een aanmaken met het commando sudo groupadd mythras, mythras verandert u uiteraard naar uw eigen gekozen groep.
In bovenstaand voorbeeld zijn de gebruikers kathy en maaike toegevoegd aan het OS en in de groep thuis geplaatst.
U gaat elke gebruiker een paswoord toewijzen omdat samba dit vraagt, dit doet u met het commando: sudo smbpasswd –a wil u dat de gebruiker een nul paswoord heeft, gebruikt u het commando: sudo smbpasswd –an
VB: sudo smbpasswd –an maaike
Sudo smbpasswd –a kathy
Sudo smbpasswd -a bitfix
Sudo smbpasswd -a pi
Samba zal u vragen het paswoord 2x in te voeren, eens dit gebeurd is, zijn de gebruikers toegevoegd aan samba en kan u verder met de shares aan te maken.
5.1.1 Directories
De gebruikers en de groepen zijn aangemaakt, op deze manier gaat u meer inzicht krijgen voor de aan te maken directories.
De volgende Directories gaat u aanmaken:
De publieke shares en de private shares, volgende bestaan uit:
De publieke shares
- Video
- Afbeeldingen
- Muziek
- Allerlei
De private shares
- Bitfix
- Pi
- Maaike
- Kathy
5.1.2 Directories aanmaken
Volgende directories maakt u aan:
Sudo mkdir /mnt/externaldrive/publiek
Sudo mkdir /mnt/externaldrive/prive
Met ls –l /mnt/externaldrive kan u zien dat de 2 directories zijn aangemaakt.
U gaat nu onder de directory publiek (cd /mnt/externaldrive/publiek) onderstaande mappen aanmaken.
- Video
- Afbeeldingen
- Muziek
- Allerlei
Eens onder de directory /mnt/externaldrive/publiek voert u volgende commando’s uit:
Sudo mkdir video afbeeldingen muziek allerlei
Daarna gaat u onder de directory prive (cd /mnt/externaldrive/prive) volgende mappen aanmaken. U gebruikt uiteraard uw eigen aangemaakte gebruikers.
Sudo mkdir bitfix maaike pi kathy vergeet de spaties niet.
U zal ondertussen al gezien hebben dat de directory’s en mappen onder /mnt/externaldrive toegewezen zijn aan root, dit komt omdat momenteel root de eigenaar is van deze directory’s en mappen alsook de groep. Dit gaat u nu juist zetten.
5.1.3 permissies
Om de rechten juist te zetten gebruikt u volgende commando’s, u gaat eerst naar cd /mnt/externaldrive/.
Sudo chgrp –R thuis publiek
Sudo chmod –R 755 publiek
U zal zien dat de groep root nu is aangepast naar beheerder, beheerder is de groep die u hebt aangemaakt door het commando sudo groupadd thuis ( of uw eigen groepsnaam). Door het commando sudo chmod -R 755 publiek, gaat u de rechten op de directory en alles wat eronder ligt aanpassen. Hierdoor heeft de gebruiker alle rechten en kunnen de groep en others niet schrijven.
- -R is recursief en zal de opdracht van onder naar boven uitvoeren, hierdoor hebben alle onderliggende mappen dezelfde rechten.
755 zijn de rechten, deze zijn octaal in unix systems, schematisch voorbeeld.
Dit doet u ook voor de directory prive, uiteraard gaat u onder de directory /mnt/externaldrive staan.
Sudo chgrp –R thuis prive
Sudo chmod –R 755 prive
Daarna gaat u de rechten van de gebruikers aanpassen onder de directory /mnt/externaldrive/prive,.
In de afbeelding hieronder ziet u hoe de rechten nog van root zijn, terwijl de groep als is aangepast naar thuis.
eens onder directory prive of hoe u deze ook genoemd heeft, gaat u voor elke gebruiker de rechten aanpassen zodat de gebruiker eigenaar is van zijn eigen directory.
- Sudo chown -R maaike:thuis maaike/
- Sudo chown -R pi:thuis pi/
- Sudo chown -R bitfix:thuis bitfix/
- Sudo chown -R kathy:thuis kathy/
Na het ingeven van de commando’s moet dit er als volgt uitzien.
5.2 Smb.conf
Shares aanmaken in samba is niet zo moeilijk, het belangrijkste is dat u een back-up genomen heeft van het configuratiebestand. Zo kan u steeds, wanneer u een fout begaan hebt terug naar het origineel. Scrol even naar boven om het te bekijken wanneer u dit hebt overgeslagen.
U opent het smb configuratiebestand door het commando: sudo nano /etc/samba/smb.conf er zal een configuratiebestand openen. Nano zorgt hiervoor, deze is een editor.
Het eerste wat u doet is de workgroup instellen, normaal heet deze standaard in een windows netwerk workgroup. Moest u deze aangepast hebben naar iets anders dan voert u dit in, in het configuratiebestand.
Samba moet weten welke shares je wil delen, u gaat onderaan het configuratiebestand voor elke share een nieuwe blok toevoegen. Dit blok bevat de locatie, toegangscontrole etc. van de share.
U zal in alle waarschijnlijkheid mogelijke data willen uitwisselen aan vrienden, kennissen of familie. Hiervoor hebt u de directory publiek aangemaakt met de onderliggende mappen.
- Allerlei
- Afbeeldingen
- Foto
- video
Nu de share: onderaan uw configuratiebestand plaatst u…
[Public share]
comment = Public share
path = /mnt/externaldrive/publiek/
writable = yes
write list = @thuis
public = yes
browsable = yes
guest ok = yes
Eens u dit heeft ingevoerd, drukt u op CTRL O en enter om op te slaan, CTRL X om af te sluiten. U herstart de samba server met het commando: sudo /etc/init.d/samba restart.
Nu hebt u de publieke share geplaatst, tijd voor de private shares, onder de publieke share die u net gemaakt hebt gaat u voor elke gebruiker die u hebt aangemaakt een share plaatsen in het smb.conf bestand.
U plaatst het volgende onderaan het configuratiebestand…
[Prive kathy]
comment = prive kathy
path = /mnt/externaldrive/prive/kathy
valid users = kathy
read only = no
writable = yes
Wederom drukt u op CTRL O en enter om op te slaan, CTRL X om af te sluiten. U herstart de samba server met het commando: sudo /etc/init.d/samba restart.
6. Samba shares benaderen Windows
Hoe kan u deze aangemaakte shares nu banaderen in Windows, hiervoor opent u de verkenner.
Aan de linker zijde, onder netwerk zal u de naam van je raspberry pi zien staan. Standaard zal dit RASPBERRY zijn. Staat deze er niet, gaat u bovenaan het IP adres invoeren van de raspberry pi.
Eens u entert komt u onder de directory RPI en zal u de shares kunnen bekijken, de private mappen zullen toegankelijk zijn onder uw gebruikersnaam en paswoord.
Als u niet inlogt in uw private map, zal u niet kunnen schrijven onder de publieke share, deze zal u aanzien als guest.