LINUX

How to Set Up a Network Shared Folder on Ubuntu With Samba

0

If you have ever wanted to easily share files on your home network across multiple operating systems, then look no further than Samba.

This guide will show you how to set up a network shared folder on Ubuntu Linux using Samba. With the Samba server, you can easily share files on your network, regardless of whether you are using Windows, macOS, or Linux.

What Is Samba?

Samba is a file-sharing service that implements open source versions of the SMB suite of protocols, which was originally developed by Microsoft and IBM. Samba contains programs that allow it to interoperate with Microsoft Windows file sharing protocols.

Samba also allows you to easily communicate with other clients using standard TCP/IP networking.

Step 1: Installing Samba

This guide will use Ubuntu Linux 20.04 LTS, but the steps should work even if you are using Ubuntu 16.04 or later. Begin by updating your package source information.

sudo apt update

Then, install Samba using the command below:

sudo apt install samba

To check if Samba has been successfully installed, run the following command:

smbd --version

The output should be similar to the one below.

samba_version_output-1

Step 2: Configuring Samba

To be able to share files securely with other network devices, you have to configure the Samba server. The main configuration file for Samba is located at /etc/samba/smb.conf on your PC. This guide uses the Vim text editor for editing the Samba configuration file, but feel free to use any other text editor of your choice.

Note: You need to have administrative privileges to edit the configuration file.

sudo vim /etc/samba/smb.conf

Add the following lines to the bottom of the config file.

[sambashare]comment= Network Shared Folder by Samba Server on Ubuntupath = /home/your_username/sambashareforce user = smbuserforce group = smbgroupcreate mask = 0664force create mode = 0664directory mask = 0775force directory mode = 0775public = yesread only = no

Remember to update the path parameter with your username. You can get your username by running the following command:

echo $USER

To exit the Vim editor after making your changes, simply type :wq and press the Enter key.

Understanding the Configurations

Here is a brief description of the configuration lines that you just added.

  • Section: A new section in the configuration file is represented by square brackets ([ ]). In this case, the section is [sambashare].
  • Comment: This line of code provides a brief outline of what this section is about. Especially, it is useful if you have several shared directory sections in the config file.
  • Path: This is the path to the directory of your designated network shared folder.
  • Force user: The system user that the Samba server will use for sharing files.
  • Force group: The name of the group to which the Samba system user will belong.
  • Create mask: This parameter will set permissions for newly created files in the shared folder. In this case, the value is 0664 which means that the owner of the file and the group will have read and write permissions while other users will only have read permissions.
  • Force create mode: Works in conjunction with the create mask parameter in order to set the correct file permissions.
  • Directory mask: This parameter determines the permissions for folders in the shared folder. Permissions of 0775, means that the owner and the group have read, write, and execute permissions, while others have read and execute permissions only.
  • Force directory mode: This parameter works in collaboration with the directory mask to make sure that the correct directory permission is set.
  • Public: This parameter specifies that this is a public folder on your network and that other devices can access it.
  • Read only: Specifies the permissions for modifying the files within the shared folder.

Step 3: Creating Samba Resources

Having configured the Samba server, now you have to create the necessary resources such as the Samba user and the directory to share. These resources will facilitate the process of sharing a folder on the network.

1. Shared Folder

You need to create the shared folder in the path specified in the Samba config file above. This guide uses a shared folder named sambashare located in your home directory.

Navigate to your home directory using the cd command.

cd ~

Then create the shared directory using the command below:

mkdir -p sambashare

2. Samba User and Group

The next step is to create the Samba system user and group specified in the configuration file.

You can create the Samba system group using the following command:

sudo groupadd --system smbgroup

Next, create the Samba system user using useradd.

sudo useradd --system --no-create-home --group smbgroup -s /bin/false smbuser 

The command above creates a system user and adds the user to the Samba group created above. Also since this is a system user, no home directory will be created.

3. Changing the Shared Folder Owner

Once the Samba user and group are in place, you can now change the shared folder owner to the new user smbuser and the group to smbgroup. You can achieve this using the command below:

sudo chown -R smbuser:smbgroup ~/sambashare

Finally, issue the command below to give the group write access to the shared folder and the content inside it.

sudo chmod -R g+w ~/sambashare

Step 4: Restarting the Samba Service

You should restart the Samba service for the changes in the Samba configuration file to take effect.

sudo systemctl restart smbd

After the service restarts, you can check its status with the command below:

sudo systemctl status smbd
samba_service_status_on_ubuntu_linux

Note: If you have your firewall enabled, you should also add Samba to your enabled rules using the ufw command.

sudo ufw enable samba

Step 5: Accessing the Shared Folder

Your shared folder is now accessible by the devices on your network.

On Windows

In Windows, you can access the shared folder using Windows Explorer. You can start file explorer using the Windows + E keyboard shortcut.

In the address bar, type \\ip_address_of_pc_with_shared_folder\sambashare.

Remember to replace with the correct IP address and shared folder name.

accessing_shared_folder_in_file_explorer

The system will also ask you to enter the username and password of the user on the Linux PC.

authentication_to_access_a_shared_folder

On Ubuntu

On Ubuntu Linux, open the default file manager and click on the Other Locations button. Then, in the Connect to Server input, enter an IP address in the following format:

smb://ip_adresss_of_pc_with_shared_folder/sambashare
connect_to_shared_folder_server_on_linux

You can either connect as a registered user or anonymous. Keep in mind that if you select Registered User from the dropdown, you'll have to specify the credentials of the user.

login_anoymously_to_shared_folder_on_linux

On macOS

Mac users can access the shared folder easily as well. In the Finder menu, click on the Network tab, and the computer with the public shared folder will be listed. Select it and you should be able to access the files.

samba_shared_folder_on_macos

Sharing Files Between Multiple Devices Efficiently

This guide has looked at how to share files on a network using Samba. With Samba, you can share files on a network regardless of the operating system that you are running on the devices.

Not only Linux, but you can also configure a shared network folder on your Windows machine.

admin

7 Ways to Fix “Your PC Did Not Start Correctly” Error

Previous article

How to Make a Background Transparent in Adobe Illustrator

Next article

You may also like

Comments

Leave a reply

Your email address will not be published. Required fields are marked *

More in LINUX

Login/Sign up