How to Set Up Linux File Sharing With Samba

Sharing files from the Linux desktop doesn’t have to be a challenge

What to Know

  • Install: Open Terminal, update and upgrade, reboot if necessary, and type sudo apt-get install samba -y.
  • Start and configure: Type sudo nano /etc/samba/smb.conf, add a workgroup, hostname, and user, restart Samba.
  • Share: Right-click Documents > Local Network Share > Share this folder > Create Share > Add the permissions automatically.

Linux was made to be on a network, which is why it offers a high level of security and flexibility. If you have multiple machines on a single network, then you might need to share folders from your Linux desktop. Thanks to the inherent flexibility of Linux, you can do this easily with the help of Samba.

What Is Samba?

Samba is the Linux implementation of the Server Message Block (SMB) protocol, which is used for network file sharing. On the Windows operating system, this is simply referred to as SMB. Samba is free, open-source software that is readily available for installation from within most standard repositories.

Originally developed by Andrew Tridgell, Samba provides file and print services and can (as of Samba version 4) integrate with a Microsoft Windows Server domain (either as a Domain Controller or as a domain member).

For some Linux desktop distributions, setting up Samba is a few quick clicks away from success. Before we examine how to set this up the easy way, let’s go the other route. We’ll be demonstrating by sharing files between Elementary OS and Ubuntu Desktop 18.04.

How to Install Samba

It should be noted, that on the Ubuntu Desktop iteration of Linux, you won’t have to go through the manual process of installing Samba. Because this isn’t the case for every Linux desktop, let’s install.

Screenshot of a Linux terminal window.
  1. Log into your Linux desktop and open a terminal window.

  2. Update and upgrade with the command:

    sudo apt-get update && sudo apt-get upgrade -y
  3. When the upgrade completes, reboot the desktop (necessary only if the kernel is upgraded). Install Samba with the command:

    sudo apt-get install samba -y
    Installing Samba on Linux.
  4. Start and enable Samba with the commands:

    sudo systemctl start smbd
    sudo systemctl enable smbd
  5. Samba is now ready to be configured.

How to Configure Samba

Samba isn’t all that difficult to configure. When using GNOME on Ubuntu Desktop, you won’t have to bother with manually configuring Samba, via a configuration file. However, on Elementary OS (and other distributions), it is required to configure Samba from a text-based configuration file. Here’s how:

  1. Open a terminal window on your desktop.

  2. Issue the command:

    sudo nano /etc/samba/smb.conf
  3. Locate the line workgroup = WORKGROUP and change it to something unique (or, if you already have a workgroup on your network, change it to that).

    workgroup = WORKGROUP
  4. Below the workgroup line, add the line netbios name = NAME (Where NAME is the name, or hostname, of your desktop computer).

  5. Let’s say you want to share the Documents folder in your home directory (we’ll call that /home/jack/Documents, so those using the share can create new folders and files. At the bottom of the smb.conf file, add:

                   comment = NAME Documents
    path = /home/jack/Documents
    writeable = yes
    browseable = yes
    guest ok = yes
    create mask = 0775

    Where NAME is the same name you used for the netbios option. Save and close the smb.conf file.

  6. Next you need to add your user to Samba. This is done with the following two commands:

    sudo smbpasswd -a $USERNAME
    sudo smbpasswd -e $USERNAME

    You will first be prompted for your sudo password and then to type and verify a new SMB password for the user.

    Options Explained

    In the above commands, the -a option adds the user and the -e option enables the user.

  7. Finally, restart Samba with the command sudo systemctl restart smbd.

If you want to add more than just one share, create the new one below the [Documents] share, using that same configuration model.

Create a Samba Share With Ubuntu Desktop

You should now be able to connect to the newly created Samba share from any Desktop file manager on your network, that supports the SMB protocol (which is most of them). How this is done will depend upon the operating system connecting to the Samba share and the file manager used.

If Ubuntu Desktop is your distribution of choice, creating a Samba share is much easier. We’ll share the same directory (/home/jack/Documents). To do this, follow these steps:

  1. Open the file manager.

  2. Right-click the Documents folder and click Local Network Share from the menu.

    Local network share
  3. In the resulting window, select the check box for Share this folder and then check the boxes for Allow others to create and delete files in this folder and Guest access.

    Folder Sharing
  4. Type a descriptive comment in the Comment section (optional).

  5. Press Create Share.

    Folder Sharing > Create Share
  6. When prompted, press Add the permissions automatically.

    Add the permissions automatically
  7. You should now be able to access /home/jack/Documents from any desktop file manager on your network.

Was this page helpful?