How to Install and Configure Samba in Ubuntu

In the current society where things are digitalized it is common for people to share files and printers among various devices. Regardless of whether you are using a computer and its resources for personal or academic purposes, sharing files and printers is sometimes necessary. But on the other hand, it is also very simple for sharing files or printers, and at the same time, it may also be a very daunting task especially when dealing with different operating systems and devices.

Samba is a free and Open-Source software solution that allows the Linux and MS Windows operating systems to integrate with each other. Samba makes it possible to share files, printers, as well as other resources from one operating system to another read more. This tutorial will explain how to properly set Samba up on Ubuntu as well as explain how to use it with Windows computers.

Steps to install Samba in Ubuntu

Step 1: Enter the following command to install samba.

sudo apt install samba

Step 2: Setting up Samba Now that Samba is installed, we need to create a directory for it to share:

Enter the following command to do so.

mkdir /home/<username>/sambashare/

It will create a directory as samba share inside the home directory of the user <username>. This is the directory in which files and folders that you would like to share through Samba will reside.

Note: In the current draft of the script, the <username> must be substituted with the actual username of the user who owns the home directory.

Step 3: Now we have to edit the config file of samba. The configuration file for Samba is located at /etc/samba/smb.conf. To add the new directory as a share, we edit the file by running:

sudo nano /etc/samba/smb.conf

At the bottom of the file, add the following lines and save it.

[sambashare]
comment = Samba on Ubuntu
path = /home/username/sambashare
read only = no
browsable = yes

This configuration section specifies that, sambashare which is located at /home/username/sambashare, should not be read-only and can be browsed. This means that users can mount the share, view its contents and write into it using a Samba client.

Step 4: After saving the config file, restart the samba service.

sudo service smbd restart

Since there may be a firewall which can block samba traffic due to security reasons. You can add firewall rules to allow samba traffic. Enter the following command to do so.

sudo ufw allow samba

Step 5: Setting up User Accounts and Connecting to Share

As Samba doesn’t use the system account password, we need to set up a Samba password for our user account.

We can do this by entering the following command:

sudo smbpasswd -a username

Note: Replace username with the username of your system account.

Step 6: Connecting to Share,Open the default file manager and type the following into the search bar.

smb://ip-address/sambashare

Press enter to execute the command, this will prompt you to enter your credentials.

After entering the right credentials, you will be connected to the server.

Install and Configure Samba in Ubuntu – FAQs

What is Samba and why do I need it?

Samba is a free and open-source software that lets your Ubuntu system share files and printers with Windows, macOS, and other Linux machines on your network. It essentially translates between the way Ubuntu and other operating systems communicate with files, allowing them to work together seamlessly.

How do I install Samba on Ubuntu?

Installing Samba is straightforward. Open a terminal and run the following command:

sudo apt install samba samba-common-bin

This will download and install the necessary Samba packages.

How do I configure a Samba share?

Samba uses a configuration file to define how it shares folders. You’ll need to edit the main configuration file (/etc/samba/smb.conf) using a text editor like nano. Here, you’ll specify the folders you want to share, user permissions, and other options.