Skip to main content

Implement SAMBA (CIFS) Fileshares for Servers and Clients

Hands-On Lab

 

Photo of Terrence Cox

Terrence Cox

Senior Vice President of Content

Length

01:00:00

Difficulty

Intermediate

Implementing fileshares for Windows and Linux servers, plus clients is a key skill for any experienced system administrator. In this activity, we will be working to set up a Linux Samba fileshare that can then be used by a remote client to store files on. Once this activity is completed, we will see how Samba can be used to provision a fileshare for use via a Linux client.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Implement SAMBA (CIFS) Fileshares for Servers and Clients

Introduction

In this hands-on lab, we will be setting up a Linux Samba fileshare that can be used by a remote client to store files on.

Solution

Open a terminal session, and log in to the server via SSH using the credentials provided on the lab page:

bash ssh cloud_user@<PUBLIC_IP_ADDRESS>

Become root user:

sudo - u

Install Samba Packages on the Samba Server

  1. We will need several packages installed on our server to complete this activity. Install the packages with:
    sudo yum install -y samba samba-client cifs-utils
  2. Once the install completes, run the following:
    vim /etc/samba.smb.conf

Allow Network and Users to Access the Share

  1. Under [global] and after security add:

    hosts allow = 127. 10.0.1.
  2. Beneath hosts allow, change passdb backend to:

    = smbpasswd:/etc/samba/sambapassword.txt
  3. Beneath passdb backend add:

    interfaces = lo eth0

    Now we are ready to create and define [devdocs].

  4. We will need to add a new section at the end of the configuration file for our share. We can accomplish this by adding the following values:

    [devdocs]
            comment = Development documentation
            read only = no
            available = yes
            path = /devdocs
            public = yes
            valid users = devdocsuser
            write list = devdocsuser
            writable = yes
            browseable = yes
  5. Save and exit.

Create the Server Fileshare and Set Universal Read/Write Permissions

  1. On the server, we are asked to create the fileshare location for our development team's documentation. Easily accomplished with:
    sudo mkdir /devdocs

Make the Local Mount Directory on the Samba Client and Set Universal Permissions

  1. We can meet the accessibility requirement with the command:

    sudo chmod 777 /devdocs
  2. Run the following to begin adding a user:

    useradd devdocsuser
  3. Set up the password:

    smbpasswd -a devdocsuser
  4. Input the password when prompted.

    Note: We will see a message indicating that the file /etc/samba/sambapasswd.txt did not exist, but will be created for us.

  5. It is optional to test further, but we can do so with:

    sudo testparm

Start the Samba Service

  1. Start and enable smb:

    sudo systemctl start smb
    sudo systemctl enable smb

Install Samba Packages on the Samba Client Server

  1. Similar to the server install, we will need to install some packages on the client in order to use the share that we are making available from the server. We can execute the package installation via the command:
    sudo yum install -y samba samba-client cifs-utils

Test the Server Mount on the Client System via the Command Line

  1. Execute the following for the fileshare location:

    sudo mkdir /mnt/devdocs
  2. This time run:

    sudo chmod 777 /mnt/devdocs/
  3. Enter the file we will be editing:

    vim /etc/fstab

    Note: We can now add the mount to the command line, but it can also be added directly to /etc/fstab.

  4. We will need to provide a string of options to the mount command to test our access:

    sudo mount -t cifs -o user=devdocsuser,password=devdocs //10.0.1.100/devdocs /mnt/devdocs/
  5. Save and exit.

  6. Continue with:

    mount -a
  7. Once mounted, we can verify our actions with the following command to see it in the list of mounted filesystems, and then should be able to write a file, plus read it on either the client or server system:

    df -h

Conclusion

Congratulations — you've completed this hands-on lab!