How to Set Up Linux File Sharing With Samba

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

A laptop sitting on a couch.

Pixabay

Linux was made to be on a network which is why it offers a high level of security and flexibility. If you happen to have multiple machines on a single network, then you might have a need to share out folders from your Linux desktop. Thanks to that inherent flexibility of the Linux operating system, this can be easily done, with the help of 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.

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.

Log into your Linux desktop and open a terminal window.

  1. Update and upgrade with the command sudo apt-get update && sudo apt-get upgrade -y.

  2. When the upgrade completes reboot the desktop (which is only necessary if the kernel is upgraded).

    Screenshot of installing Samba on Linux.

    Install Samba with the command sudo apt-get install samba -y.

  3. Start and enable Samba with the commands:

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

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.

    Screenshot of the Samba configuration file.

    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).

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

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

                    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.

  5. 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.

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

Adding More Shares

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

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.

    Screenshot of the folder right-click menu in Ubuntu Desktop.

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

    Screenshot of the Folder Sharing window.

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

  2. Type a descriptive comment in the Comment section (optional).

  3. Click Create Share.

    Screenshot of adding file permissions automatically.

    When prompted, click Add the permissions automatically.

  4. You should now be able to access /home/jack/Documents from any desktop file manager on your network.