Installing the Samba server

In this recipe, we will learn how to install Samba as our network storage server. Samba is a collection of open source applications that implement Server Message Block (SMB) and Common Internet File System (CIFS) protocols on Unix systems. This allows Samba to be accessible across different types of network system. Samba provides various other functionalities, such as a domain controller for the networks of Windows systems. In this recipe, we will focus on using Samba as a storage server.

Getting ready

You will need access to a root account or an account with sudo privileges

If your server is using any firewall system, make sure to open the necessary network ports. Samba runs on TCP 139 and 445 and UDP ports 137 and 138. Check Chapter 2, Networking, for more details on firewall configuration.

How to do it…

Follow these steps to install the Samba server:

  1. Install the Samba server with the following command:
    $ sudo apt-get update
    $ sudo apt-get install samba -y
    
  2. After installation is complete, you can check the Samba version with the following command:
    $ smbd --version
    
  3. Next, we need to configure Samba to enable sharing on the network. First, create a backup of the original configuration file:
    $ sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.orignl
    
  4. Next, open smb.conf and replace its contents with the following:
    [global]
    workgroup = WORKGROUP
    server string = Samba Server
    netbios name = ubuntu
    security = user
    map to guest = bad user
    dns proxy = no
    [Public]
    path = /var/samba/shares/public
    browsable =yes
    writable = yes
    guest ok = yes
    read only = no
    create mask = 644
    
  5. Next, we need to create a shared directory:
    $ sudo mkdir -p /var/samba/shares/public
    
  6. Change the directory permissions to make it world writable:
    $ sudo chmod 777 /var/samba/shares/public
    
  7. Restart the Samba service for the changes to take effect:
    $ sudo service smbd restart
    

Now you can access this Samba share on the Windows client. Open Windows Explorer and in the address bar, type in \ubuntu or \your-server-ip. You should see the shared directory, Public, as follows:

How to do it…

How it works…

Samba is quite an old technology, especially in the age of Cloud storage such as Dropbox and Amazon S3. However, when it comes to private networking, Samba offers a hassle-free setup and is always available for free. All you need is a small server with some free storage space. The release of Samba 4 has added Active Directory (AD) support. Now it's possible to set up Windows AD on Linux servers. Support for AD comes with a wide range of other features, including DNS for name resolution, centralized storage, and authentication with LDAP and Kerberos.

As you can see in the preceding example, setting up Samba is quick and easy, and you can easily get started with network storage within minutes. We can install the Samba server with a single command, as Samba packages are available in the Ubuntu default package repository. After installation, we have created a new quick and dirty configuration file which defines a few parameters, such as the server name (netbios name) and a share definition. We have created a publicly-shared directory where everyone can read and write the contents.

Once you are done with installation and initial testing, make sure that you remove public sharing and enable authenticated access to your Samba shares. You don't want the server to fill up with data from unknown people. In the next recipes, we will take a closer look at user management and access control for Samba shares.

There's more…

To secure your Samba installation and limit access to your local network or subnet, you can use the following configuration parameters:

[globals]
hosts deny = ALL
hosts allow = xxx.xxx.xxx.xxx/yy 127.
interfaces = eth0 lo
bind interfaces only = Yes

This configuration limits Samba to listen only on listed interfaces. In this case, its eth0, the Ethernet network, and lo, localhost. Connection requests from all other hosts are denied.

Tools for personal file sharing

If you need a simple file sharing tool for your personal use and do not want to set up and configure Samba, then you can try using a tool named OwnCloud. It is very similar to Dropbox and is open source. It gives you web access to all your files and documents. Plus, you get desktop and mobile client apps to sync all files to a remote server.

Another good tool is BitTorrent Sync. Again, this is a file synchronization tool, but this time it is peer-to-peer file synchronization. If you really care about the privacy and security of data, then this tool is made for you. All files are synchronized between two or more systems (say, your desktop and laptop) without the use of any centralized server.

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset