This recipe shows how the Raspberry Pi can be configured to become a file server on the local network.
The Raspberry Pi with attached file storage functions well as a file server. Such a file server could be used as a central location for sharing files and documents, for storing backups of other computers, and for storing large media files such as photo, music, and video files.
This recipe installs and configures samba
and samba-common-bin
. The Samba software distribution package, samba
, contains a server for the SMB (CIFS) protocol used by Windows computers for setting up 'shared drives' or 'shared folders'. The samba-common-bin
package contains a small collection of utilities for managing access to shared files.
The recipe includes setting a file-sharing password for the user pi
and providing read/write access to the files in pi
user's home directory. However, it does not set up a new file share or show how to share a USB disk. The next recipe shows how to do that.
After completing this recipe, other computers can exchange files with the default user pi
.
The following are the ingredients:
This recipe does not require the desktop GUI and could either be run from the text-based console or from within an LXTerminal
.
If the Raspberry Pi's Secure Shell server is running and it has a network connection, this recipe can be remotely completed using a Secure Shell client (see Chapter 2, Administration).
The following are the steps for creating a file server:
apt-get install samba samba-common-bin
Download and install samba
with the other packages that it depends on. This command needs to be run as a privileged user (use sudo
).
In the preceding screenshot, the
apt-get
command is used to install the samba
and samba-common-bin
software distribution packages.
nano /etc/samba/smb.conf
Edit the samba
configuration file. The smb.conf
file is protected and needs to be accessed as a privileged user (use sudo
).
The preceding screenshot starts the nano
editor to edit the /etc/samba/smb.conf
file.
security = user
line. Uncomment the line (remove the hash, #
, from the beginning of the line).The preceding screenshot of the Samba configuration file shows how to change samba security to use the Raspberry Pi's user accounts.
read only = yes
line to be read only = no
, as shown in the following screenshot:The preceding screenshot shows how to change the Samba configuration file to permit adding new files to user shares (read only = no
).
nano
editor./etc/init.d/samba reload
Tell the Samba server to reload its configuration file. This command is privileged (use sudo
).
In the preceding screenshot, the Samba server's configuration file is reloaded with the /etc/init.d/samba
command.
smbpasswd –a pi
This command needs to be run as a privileged user (use sudo
). Enter the password (twice) that will be used for SMB (CIFS) file sharing.
The preceding screenshot shows how to add an SMB password for the pi
user.
The preceding screenshot starts mapping a network drive to the Raspberry Pi on Windows 7.
\raspberrypipi
as the network folder. Choose an appropriate drive letter. The example uses the Z:
drive. Select Connect using different credentials and click on Finish, as shown in the following screenshot:The preceding screenshot finishes mapping a network drive to the Raspberry Pi.
In the screenshot, a dialog box is displayed for logging in to the Raspberry Pi with the SMB (CIFS) username and password.
Only the home directory of the pi
user is accessible at this point. The next recipe configures a USB disk for using it as a shared drive.
This recipe begins by installing two software distribution packages – samba
and samba-common-bin
. This recipe uses the apt-get install
command; however, the aptitude
package management application could also be used to install software packages.
The Samba package contains an implementation of the Server Message Block (SMB) protocol (also known as the Common Internet File System, CIFS). The SMB protocol is used by Microsoft Windows computers for sharing files and printers.
The samba-common-bin
package contains the smbpasswd
command. This command is used to set up user passwords exclusively for using them with the SMB protocol.
After the packages are installed, the Samba configuration file /etc/samba/smb.conf
is updated. The file is updated to turn on user security and to enable writing files to user home directories.
After the configuration file is updated, the Samba server is told to reload its configuration. At this point, the Raspberry Pi should be visible to other machines on the local network that are using the SMB protocol. However, the passwords for the authorized users have not yet been configured.
The smbpasswd
command is used to add (-a
) the pi
user to the list of users authorized to share files with the Raspberry Pi using the SMB protocol. The passwords for file sharing are managed separately from the passwords used to log in to the Raspberry Pi either directly or remotely. The smbpasswd
command is used to set the password for Samba file sharing.
After the password has been added for the pi
user, the Raspberry Pi should be accessible from any machine on the local network that is configured for the SMB protocol.
The last steps of the recipe configure access to the Raspberry Pi from a Windows 7 PC using a mapped network drive. The UNC name for the file share, \raspberrypipi
, could also be used to access the share directly from Windows Explorer.
This is a very simple configuration for sharing files. It enables file sharing for users with a login to the Raspberry Pi. However, it only permits the files in the user home directories to be shared. The next recipe describes how to add a new a file share.
In addition to the SMB protocol server, smbd
, the Samba software distribution package also contains a NetBIOS name server, nmbd
. The NetBIOS name server provides naming services to computers using the SMB protocol. The nmbd
server broadcasts the configured name of the Raspberry Pi, raspberrypi
, to other computers on the local network.
In addition to file sharing, a Samba server could also be used as a Primary Domain Controller (PDC) – a central network server that is used to provide logins and security for all computers on a LAN. More information on using the Samba package as a PDC can be found on the links given next.
http://en.wikipedia.org/wiki/Samba_(software)
A Wikipedia article on the Samba software suite.
http://manpages.debian.net/cgi-bin/man.cgi?query=nmbd
The Debian man page for nmbd
.
http://manpages.debian.net/cgi-bin/man.cgi?query=samba
The Debian man page for samba
.
http://manpages.debian.net/cgi-bin/man.cgi?query=smb.conf
The Debian man page for smb.conf
.
http://manpages.debian.net/cgi-bin/man.cgi?query=smbd
The Debian man page for smbd
.
http://manpages.debian.net/cgi-bin/man.cgi?query=smbpasswd
The Debian man page for smbpasswd
.
http://www.debian.org/doc/manuals/debian-reference/ch04.en.html
The Debian Reference Manual article on system initialization.
18.218.196.182