Reader small image

You're reading from  Linux Networking Cookbook

Product typeBook
Published inJun 2016
Publisher
ISBN-139781785287916
Edition1st Edition
Concepts
Right arrow
Authors (2):
Gregory Boyce
Gregory Boyce
author image
Gregory Boyce

Gregory Boyce is a technologist with nearly 20 years' experience using and managing Linux systems. When he's not at work or spending time with his wife and two daughters, he plays around with new technologies. Gregory has spent the last 15 years working at Akamai Technologies, where he has worked in roles ranging from Network Operations, Internal IT, Information Security, Software Testing, and Professional Services. Currently, he heads up the Linux OS team that manages Akamai's custom Linux operating system, which runs on their massively distributed customer-facing network.
Read more about Gregory Boyce

View More author details
Right arrow

Chapter 7. Setting up File Storage

In this chapter, we are going to cover:

  • Serving files with SMB/CIFS through Samba

  • Granting authenticated access

  • Setting up an NFS server

  • Configuring WebDAV through Apache

Introduction


Once you have a network with multiple devices, it is useful to be able to share files easily between them and between users. Building a centralized file server achieves this goal as well as provides a central point for backing up your data. In this chapter, we will explore several available protocols for storing files. We will start with the SMB/CIFS protocols, commonly used by Windows systems, and work our way to services specifically designed for synchronizing mobile clients.

Serving files with SMB/CIFS through Samba


We are going to start by setting up a simple read-only file server using Samba, and then we will expand on it from there. If you are not familiar with SMB/CIFS, you may know it by another name, Windows File Sharing. This is the protocol, which Microsoft uses for its built-in file sharing, but re-implemented by the Samba project.

How to do it…

  1. Install Samba:

    sudo apt-get install samba
    
  2. Edit /etc/samba/smb.conf:

    [global]
      server role = standalone server
      map to guest = Bad User
      syslog = 0
      log file = /var/log/samba/log.%m
      max log size = 1000
      dns proxy = No
      usershare allow guests = Yes
      panic action = /usr/share/samba/panic-action %d
      idmap config * : backend = tdb
    [myshare]
      path = /home/share
      guest ok = yes
      read only = yes
  3. Restart smbd:

    sudo service smbd restart
    
  4. You should now be able to browse the share like you used to do in Windows file share.

How it works…

The Global section of the above configuration is a slimmed-down version of the...

Granting authenticated access


Samba supports granting authenticated access to shares in addition to making them available as public shares.

How to do it…

  1. Select the account that you want to use for authentication. All Samba share accounts must be accompanied by a Unix account. In this case, we'll user a new user called testuser:

    sudo useradd testuser
    
  2. Create a separate Samba-specific password for that account:

    sudo smbpasswd –a testuser
    
  3. Modify smb.conf to set the valid users for the share:

    [myshare]
      path = /home/share
      guest ok = yes
      read only = yes
       valid users = testuser
  4. Access the share once again; confirming that this time, you are prompted for a username and password.

How it works…

As mentioned in the preceding, Samba users must be backed by a system user account that is known to PAM. This could mean a user in /etc/passwd, or it could mean a user account coming from some sort of directory service. In this case, we are going to create a dedicated user account.

Authentication however is...

Setting up an NFS server


NFS, or Network File System, was initially created by Sun Microsystems to allow clients to access remote file shares on Unix systems back in the 80s. NFS is trivial to set up and is typically rather fast, but it can introduce some interesting security issues if it is not done correctly.

How to do it…

  1. Install NFS server:

    sudo apt-get install nfs-kernel-server
    
  2. Configure shares within /etc/exports:

    /directory/to/share client(options)
    
  3. Install the NFS client software:

    sudo apt-get install nfs-common
    
  4. Mount the share:

    mount -t nfs4 server:/directory/to/share /mountpoint
    

How it works…

The nice thing about NFS is how trivial it is to set up. You simply install the NFS server, configure /etc/exports and go. The only real details to learn and understand are some of the options available and their implications:

  • Path to share: This is the absolute path to the directory on the server, which you want to export. For ease of maintenance, it is recommended that you add a level of indirection...

Configuring WebDAV through Apache


WebDAV was initially created as a protocol for managing web server content over http/https. In other words, it grants you the ability to add, remove, or edit HTML and support web content remotely.

From there, the usage expanded to provide access to general file services as well. For example, Apple's iDisk service (part of iTools/.Mac/MobileMe) supported accessing your files through any WebDAV client. This support unfortunately ended when iDisk was retired with the transition to iCloud.

WebDAV clients are built into Mac OS X and Windows as well as the file managers for Gnome, KDE and many other Linux desktop environments. You can even find Linux console tools, which support the protocol or mount it directly on your filesystem using the davfs2 filesystem driver.

How to do it…

We are going to start by assuming that you already have Apache running. If you do not, then please read the chapter on Apache configuration prior to starting. You will also want to ensure...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Linux Networking Cookbook
Published in: Jun 2016Publisher: ISBN-13: 9781785287916
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Gregory Boyce

Gregory Boyce is a technologist with nearly 20 years' experience using and managing Linux systems. When he's not at work or spending time with his wife and two daughters, he plays around with new technologies. Gregory has spent the last 15 years working at Akamai Technologies, where he has worked in roles ranging from Network Operations, Internal IT, Information Security, Software Testing, and Professional Services. Currently, he heads up the Linux OS team that manages Akamai's custom Linux operating system, which runs on their massively distributed customer-facing network.
Read more about Gregory Boyce