303.1 File Share Configuration (weight: 4)

Tech Tutorial: 303.1 File Share Configuration (weight: 4) #

Introduction #

In this tutorial, we will dive into setting up and configuring CIFS (Common Internet File System) file shares using Samba on a Linux system. Samba is a free software re-implementation of the SMB networking protocol, and provides file and print services to SMB/CIFS clients. It allows the Linux system to interact with Windows clients and act as a server for files and printers.

Prerequisites #

  • A Linux system with administrative privileges.
  • Samba installed on your Linux system.
  • Basic knowledge of Linux command line and file permissions.

Key Knowledge Areas #

  • Installation and configuration of Samba.
  • Management of Samba users.
  • Creation and configuration of CIFS file shares.

Utilities #

  • smb.conf
  • smbpasswd
  • testparm
  • smbclient

Step-by-Step Guide #

Step 1: Installing Samba #

To install Samba on a Debian-based system, use the following command:

sudo apt-get update
sudo apt-get install samba

For Red Hat-based systems, you can use:

sudo yum update
sudo yum install samba

Step 2: Configuring Samba #

The main configuration file for Samba is /etc/samba/smb.conf. You need to edit this file to set up your file shares.

  1. Backup the original configuration file:

    sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.backup
    
  2. Edit the configuration file:

    Open the file with your favorite text editor, for example:

    sudo nano /etc/samba/smb.conf
    

    Add the following configuration to set up a simple share:

    [global]
        workgroup = WORKGROUP
        server string = Samba Server %v
        netbios name = linuxbox
        security = user
        map to guest = bad user
        dns proxy = no
    
    [shared]
        path = /srv/samba/shared
        writable = yes
        guest ok = yes
        guest only = yes
        read only = no
        force user = nobody
    

    This configuration does the following:

    • Sets the workgroup and server name.
    • Configures the server to use user-level security.
    • Defines a share named [shared] that is accessible by guests.
  3. Check the configuration for errors:

    sudo testparm
    

Step 3: Adding Samba Users #

To access the Samba shares, users must be added to the Samba user database.

  1. Create a new Linux user (if necessary):

    sudo adduser samuser
    
  2. Add the user to Samba:

    sudo smbpasswd -a samuser
    

    When prompted, enter and confirm the password for the Samba user.

Step 4: Managing Samba Service #

Start, stop, and restart the Samba service as needed:

sudo systemctl start smbd
sudo systemctl stop smbd
sudo systemctl restart smbd

Step 5: Accessing the Share #

Use smbclient to access the share from the command line:

smbclient //localhost/shared -U samuser

Enter the password when prompted, and you should have access to the shared directory.

Conclusion #

In this tutorial, you’ve learned how to set up and configure a Samba server to provide CIFS file shares. You’ve installed Samba, configured a file share, managed Samba users, and accessed the share using smbclient. This setup is fundamental for creating a file-sharing network in a mixed environment with Windows and Linux systems.