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.

Putty
PuTTY is a free telnet- SSH client. It is software that anyone can connect to another computer, usually these are servers with a UNIX-based operating system. PuTTY is a replacement for a terminal (also called Teletype, TTY named), a machine that was used for the introduction of the personal computer to connect to a server. The connection between the terminal and the server software now proceeds via the SSH protocol, which is seen as a safer replacement for the obsolete telnet protocol. PuTTY has no installation and can be put down anywhere on the hard drive. The software is available for Windows and Unix-like besturingssystemen.https://nl.wikipedia.org/wiki/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.

stat ip

2.2.1 What information do you need:

the following command:

Ifconfig

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
Klasse D en E
The class D addresses are reserved for multicast groups (mainly used to define routers of the same family). A multicast group may have one, include multiple or no single host. Of 4 most significant bits of a class D address are always values 1 1 1 0. The remaining bits are allocated in a unique manner to each of the groups of hosts. There is not a single bit which belongs to the network or multicast hosts in operations. Only the hosts registered for the multicast address accept the packet. Microsoft makes use of addresses from the class D for applications that make use of a multi-point diffusion to hosts in an intranet, more specifically, WINS. Another example of a multicast distribution of data, the routing protocol EIGRP (Enhanced Interior Gateway Routing Protocol) used by CISCO routers. The routers can thus communicate and exchange routieringsgegevens dynamically without knowing the topology of the network before. The discovery of the topology of the intranet is realized d.m.v. multicast addresses. The class E addresses are experimentally. The E class is not meant for general use, This class is reserved for future use. The most significant bits in an address of the E class have always the binary warden 1 1 1 1. http://users.telenet.be/marc.persiau/IT/TCPIP/tcpip01.htm
Now that you have gathered information in your possession, you can execute the following command:

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.

dhcpdc

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

NTFS
NTFS-3G is an open source driver for NTFS partitions on Linux, FreeBSD or to read other Unix-based operating systems, Write and Create. The NTFS-3G project's first priority is to ensure the reliability of data and the driver. For this, many tests are done for each release. https://nl.wikipedia.org/wiki/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

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.

df -Th

4.1.2 Ext4 mount

 

Ext4
Fourth Extended File System oftwel ext4 is a file system used by Linux. Ext4 was developed as an extension and improvement of the ext3 filesystem; was chosen because of the many improvements for a new name: ‘ext4’, otherwise it too would be different from the default ext3. In 2006 was seriously begun development. In 2008 ext4 support was added to the Linux kernel and 2009 koos Ubuntu ‘ext4’ as standaardbestandssysteem. Year 2014 Ext4 is the de facto file system for Linux distributions. Through EXT2FSD support for Ext4 can be added to Windows. https://nl.wikipedia.org/wiki/Ext4

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.ext4 ext42


 

 

 

 

 

 

 

 

 

 

 

 

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

 

fstab
Het configuratiebestand /etc/fstab bevat informatie om het ‘koppelen’ van schijfpartities en netwerkopslaglocaties te automatiseren. Met ‘koppelen’ wordt hier bedoeld het beschikbaar maken van een (fysiek) deel van een harde schijf (schijfpartitie) of netwerkopslaglocatie, via een zogenaamd koppelpunt, een map ergens in de boomstructuur van het actieve bestandssysteem. Dit artikel is slechts een inleiding tot het gebruik van /etc/fstab. • In het algemeen wordt /etc/fstab gebruikt voor ingebouwde schijven, CD en DVD apparatuur, en voor het koppelen van op het netwerk beschikbare opslaglocaties (samba/nfs/sshfs). Verwijderbare opslagapparaten zoals USB-stickskunnen met ‘fstab’ worden gekoppeld maar deze worden normaal gesproken door de ‘gnome-volume-manager’ gekoppeld. Dit valt buiten dit artikel. • Opties voor het koppelen met de mount opdracht en voor /etc/fstab zijn uitwisselbaar. • Schijfpartities in /etc/fstab kunnen worden ingesteld om tijdens het opstarten gekoppeld te worden. • Als een apparaat of partitie NIET is opgenomen in /etc/fstab kan alleen de beheerder (met sudo) deze koppelen. • Gebruikers kunnen een apparaat of schijfpartitie alleen koppelen als deze daarvoor met de juiste opties zijn opgenomen in /etc/fstab. • Regels die beginnen met een hekje (#) worden gezien als commentaar. Op deze regels kan een opmerking geplaatst worden. Bijvoorbeeld de reden waarom een partitie op een bepaalde plek gekoppeld is.

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.

fstab

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.

useradd

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.

ls mnt

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.

octaal

 

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,.

TIP
TIP voor Debian Wheezy: Guest account Onder ####### Authentication ####### haalt u bij security ¬= user, het # weg. onder security = user plaatst u dan guest account = nobody

In de afbeelding hieronder ziet u hoe de rechten nog van root zijn, terwijl de groep als is aangepast naar thuis.

rechten root

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.

rechten root aangepast

 

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 config

 

TIP
TIP voor Debian Wheezy: Guest account Onder ####### Authentication ####### haalt u bij security ¬= user, het # weg. onder security = user plaatst u dan guest account = nobody

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.

smb config 2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

woordje uitleg over publieke share
[Public share] Onder deze naam krijgen de gebruikers de share te zien. comment = video share Dit spreekt voor zich, is gewoon commentaar path = /mnt/externaldrive/publiek/video Dit is de folder directory die we hebben aangemaakt, deze wordt gelinkt met de sharenaam. writable = yes Dit wil zeggen dat de gebruikers bestanden kunnen toevoegen. write list = @thuisgebruikers Dit zijn de toegestane gebruikers die de bestanden kunnen toevoegen, dit wil ook zeggen dat als je guest bent niet kan toevoegen of deleten. public = yes De map is publiek voor alle gebruikers die in het smbpasswd bestand staan, dus ook voor de guests want zij hebben het nobody account. browsable = yes De share is zichtbaar voor iedereen.
woordje uitleg private share
[kathy] Onder deze naam krijgen de gebruikers de share te zien. Comment = prive kathy Dit spreekt voor zich, is gewoon commentaar. path = /mnt/externaldrive/prive/kathy Dit is de folder directory die we hebben aangemaakt, deze wordt gelinkt met de sharenaam. valid users = kathy Dit laat enkel u toe in de map, de schrijf, lees en uitvoer rechten hebt u al door de permissies van de groep die u eerder ingesteld hebt op de map zelf. read only = no Dit is een soort van “Insurance” dat u zeker niet alleen leesrechten hebt voor elke gebruiker geeft u zoals bovenstaand een eigen share in.

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.

verkenner

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.

share kathy

Leave a Reply

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