Difference between revisions of "R-Pi NAS"

From eLinux.org
Jump to: navigation, search
m (Enable security on the Samba server on the RPi)
Line 4: Line 4:
 
'''Raspberry Pi Network Attached Storage'''
 
'''Raspberry Pi Network Attached Storage'''
  
This is very preliminary, do not try to follow these instructions.
+
'''These instructions have not been tested on a Raspberry Pi yet.'''
  
 +
These instructions were tested in a Debian environment. They will probably need to be changed slightly for a Fedora environment.
  
 +
If you wish to test these instructions in Ubuntu, remember that you must enter superuser mode first, by entering the command
 +
sudo -i
  
  
Line 44: Line 47:
 
=Overview of this project=
 
=Overview of this project=
 
#General Preparation
 
#General Preparation
#Configuring the Samba server on the RPi
+
#Enable security on the Samba server on the RPi
 +
#Configure private storage areas on the RPi
 +
#Configure a public storage area on the RPi
 
#Configuring the Samba client on a Windows PC
 
#Configuring the Samba client on a Windows PC
 
#Configuring the Samba client on a Linux PC
 
#Configuring the Samba client on a Linux PC
Line 88: Line 93:
 
  Press [enter]
 
  Press [enter]
  
Restart samba so that it will use the new configuration file.
+
Restart samba to use the new configuration file.
 
  restart smdb
 
  restart smdb
  
Line 94: Line 99:
 
  smdb start/running, process n
 
  smdb start/running, process n
  
==Configure a public storage area on the RPi==
 
Create a directory to store public files
 
mkdir /home/shares
 
mkdir /home/shares/public
 
chown -R root:users /home/shares/public
 
chmod -R ug+rwx,o+rx-w /home/shares/public
 
 
==Configure private storage areas on the RPi==
 
==Configure private storage areas on the RPi==
 
Configure samba to allow each user to access his home directory.
 
Configure samba to allow each user to access his home directory.
Line 122: Line 121:
 
   read only = no
 
   read only = no
  
At the end of the file, add the following lines
+
Save the edited file
 +
Press Control-X
 +
Press y
 +
Press [enter]
 +
 
 +
Restart samba to use the new configuration file.
 +
restart smdb
 +
 
 +
Expect:
 +
smdb start/running, process n
 +
 
 +
If the required user does not already exist, add a new user
 +
useradd john -m -G users
 +
passwd john
 +
You will be asked to enter the new password twice.
 +
 
 +
Allow this user to be a samba user
 +
smbpasswd -a john
 +
You will be asked to enter the new password twice.
 +
 
 +
==Configure a public storage area on the RPi==
 +
'''This section is optional. If you have more than one user, you may wish to define a public area where everybody can share files.'''
 +
 
 +
Create a directory to store public files
 +
mkdir /home/shares
 +
mkdir /home/shares/public
 +
chown -R root:users /home/shares/public
 +
chmod -R ug+rwx,o+rx-w /home/shares/publicAt the end of the file, add the following lines
 
  [public]
 
  [public]
 
   comment = Public Storage
 
   comment = Public Storage
Line 131: Line 157:
 
   directory mask = 0771
 
   directory mask = 0771
 
   read only = no
 
   read only = no
Restart samba to use the new configuration file
+
Save the edited file
  restart smbd
+
  Press Control-X
 +
Press y
 +
Press [enter]
  
Add a new user
+
Restart samba to use the new configuration file.
useradd john -m -G users
+
restart smdb
passwd john
 
You will be asked to enter the new password twice.
 
  
Allow this user to be a samba user
+
Expect:
  smbpasswd -a john
+
  smdb start/running, process n
You will be asked to enter the new password twice.
 
  
 
==Configuring the Samba client on a Windows PC==
 
==Configuring the Samba client on a Windows PC==

Revision as of 08:38, 12 February 2012

Back to RPi Projects.


Raspberry Pi Network Attached Storage

These instructions have not been tested on a Raspberry Pi yet.

These instructions were tested in a Debian environment. They will probably need to be changed slightly for a Fedora environment.

If you wish to test these instructions in Ubuntu, remember that you must enter superuser mode first, by entering the command

sudo -i


What does it do?

This project configures your Raspberry Pi to share files with any other computer on the network. You can add a large hard disk to the RPi and use this to store your important files/photos/videos in a central location.

The files on your RPi can be easily accessed from any type of computer which is connected to your network, for example a Windows PC, a Linux PC, A Mac, a smartphone, etc.

Warning: Make sure that you store your important files in more than one location. If the hard disk connected to the RPi becomes faulty, you may not be able to access your files.

What do you need?

  • A Raspberry Pi, model B.
  • A boot SD card for the Raspberry Pi.
  • A large USB-connected hard drive.
  • An Ethernet cable to connect to the local network.

What skill level is required?

This project does not require and coding or compilation. Very basic Linux and networking knowledge would be useful, but not essential.

You need to...

  • Edit configuration files on the RPi
  • Enter basic Linux commands to configure users and passwords
  • Use standard tools (Windows/Linux/Mac) to add a network drive to your PC
  • Join computers together using ethernet cables

How does it work?

The RPi is configured as a Samba server and can expose its files to any Samba client. Samba was originally a Windows-only protocol named Server Message Block (SMB), but has become popular for other operating systems.

There are other methods possible (for example ftp) but Samba is very popular because it is built into Windows and Mac OS X, and is very easy to install in all versions of Linux.

The end effect is that the PC user will be able to read and write to a new drive which appears to be locally-attached but is actually attached to the RPi.

Overview of this project

  1. General Preparation
  2. Enable security on the Samba server on the RPi
  3. Configure private storage areas on the RPi
  4. Configure a public storage area on the RPi
  5. Configuring the Samba client on a Windows PC
  6. Configuring the Samba client on a Linux PC

General Preparation

Connect the RPi to a network and check that you have an internet connection.

Command:

ping www.google.com

Expect something like

64 bytes from a.b.c.d: icmp_seq=n ttl=n time=n
64 bytes from a.b.c.d: icmp_seq=n ttl=n time=n
64 bytes from a.b.c.d: icmp_seq=n ttl=n time=n

Press Control-C to stop the ping program

If you do not see the above response, you do not have an internet connection, so this must be fixed before you can continue.

Install the samba software

Command:

apt-get install samba

Expect:

Do you want to continue? [Y/n]

Answer by pressing "y", then the [enter] key.

Enable security on the Samba server on the RPi

Note: This section is optional, but highly recommended. It forces the samba server to ask for a username and password before allowing another computer to connect.

Edit the samba configuration file

nano /etc/samba/smb.conf

Search for the section marked ##### Authentication #####

Change the text

;  security = user

to

   security = user

Note that you must use the arrow keys to move around in the nano editor, you cannot use the mouse.

Save the edited file

Press Control-X
Press y
Press [enter]

Restart samba to use the new configuration file.

restart smdb

Expect:

smdb start/running, process n

Configure private storage areas on the RPi

Configure samba to allow each user to access his home directory.

nano /etc/samba/smd.conf

Search for the section starting [homes]

For each line in this section which begin with the ";" character, delete the ";" character.

The important lines should now look like

[homes]
  comment = Home Directories
  browseable = no
  read only = yes
  create mask = 0700
  directory mask = 0700
  valid users = %S

In the [homes] section, change from

  read only = yes

to

  read only = no

Save the edited file

Press Control-X
Press y
Press [enter]

Restart samba to use the new configuration file.

restart smdb

Expect:

smdb start/running, process n

If the required user does not already exist, add a new user

useradd john -m -G users
passwd john

You will be asked to enter the new password twice.

Allow this user to be a samba user

smbpasswd -a john

You will be asked to enter the new password twice.

Configure a public storage area on the RPi

This section is optional. If you have more than one user, you may wish to define a public area where everybody can share files.

Create a directory to store public files

mkdir /home/shares
mkdir /home/shares/public
chown -R root:users /home/shares/public
chmod -R ug+rwx,o+rx-w /home/shares/publicAt the end of the file, add the following lines
[public]
  comment = Public Storage
  path = /home/shares/public
  valid users = @users
  force group = users
  create mask = 0660
  directory mask = 0771
  read only = no

Save the edited file

Press Control-X
Press y
Press [enter]

Restart samba to use the new configuration file.

restart smdb

Expect:

smdb start/running, process n

Configuring the Samba client on a Windows PC

A Windows PC uses Samba automatically, no extra software is required.

In Windows, Network Attached Storage is known as a "network drive". Open up the Windows help and search for the term "network drive", you should see something like RPI NAS Win1.JPG

If you follow the instructions, you will be asked to select a drive letter (Z: is default but you can select anything available) and the path to the network drive. RPI NAS Win2.JPG

The path is in the format \\computer_name\directory. In this example, the computer name is "big_disk" and the user wishes to attach to the directory "john". Note that the computer name may be also be in IP address format, such as "192.168.0.2".

Configuring the Samba client on a Linux PC

Not started yet.