Easy Guide: Installing Samba on Ubuntu

Published December 20, 2023

Easy dive into Installing Samba on Ubuntu.

Samba

Explore More;A Comprehensive Guide to Setting Up Java on Ubuntu

If you are part of a team connected to a network with devices running different operating systems, you have likely encountered difficulties when it comes to sharing files, printers, and resources between computers. This has undoubtedly been frustrating, and you have probably put in a lot of effort to find a solution. Well, guess what? This article provides the permanent solution you have been searching for. In just 5 minutes, you can install and configure an independent Samba file network server. With Samba, you will be able to access and share files, printers, and even Active Directory among computers running different operating systems such as Windows and Linux.

Yes, you heard it right! Samba is an open-source implementation of the Server Message Block (SMB) and Common Internet File System (CIFS) protocols. It enables seamless sharing of files, printers, and other resources among clients on the network using these protocols. So, say goodbye to the frustrations of compatibility issues and embrace the collaborative power of Samba for your Windows and Linux servers.

Why Install Samba in Ubuntu?

In the realm of opulence, the installation and configuration of Samba in Ubuntu reigns supreme as an efficacious remedy for harmoniously sharing files and an assortment of resources amidst a tapestry of systems dwelling within heterogeneous network environments, transcending the boundaries of both Windows and Linux. Allow me to unveil a selection of common incentives that endorse the installation of Ubuntu Samba:

  1. Sharing files and directories between Linux and Windows machines to address the need for exchanging and accessing files on different operating systems.
  2. Enabling printer sharing and simplifying printer management in a heterogeneous network.
  3. Providing collaboration capabilities between Linux and Windows systems.
  4. Integration with Windows networks and enhanced participation in Windows environments, including features such as domain authentication and access to shared resources.
  5. Offering centralized authentication services similar to Microsoft’s Active Directory.
  6. Controlling access to ensure authorized user access to shared resources and supporting encryption for secure data transmission.
  7. Supporting SMB/CIFS Protocols to ensure compatibility with Windows operating systems.
  8. Providing a solution for backup and storage.

Requirements for Setting Up Samba on Ubuntu

  • Ubuntu system or Ubuntu VPS with versions 18.04, 20.04, or 22.04.
  • User account with sudo privileges.
  • Meeting the RAM and CPU requirements on the server (minimum 1 gigabyte).
  • Allowing incoming TCP connections on port 445 (if using a firewall).
  • Using a text editor.
  • Access to the Linux terminal.

Easy dive into Installing Samba on Ubuntu.

Ubuntu’s official repository offers seamless support for Samba, making it incredibly convenient to install. Simply follow the steps outlined below to effortlessly install Samba on your Ubuntu system.

1. Update Package Lists

Start the Samba installation process by updating the available packages and the Ubuntu repository. Open the terminal and ensure that your package lists and the Ubuntu system are up-to-date by executing the following command:

sudo apt update

The “-y” argument is used to accept all requests automatically during installation.

2. Install Samba

To install Samba from the Ubuntu repository, use the apt package manager. Execute the following command to install ubuntu Samba once the package lists are updated:

sudo apt install samba -y

The “-y” argument is used to accept all requests automatically during installation.

3. Verify Samba installation

To ensure the successful installation of Samba in Ubuntu, run the following command:

whereis samba

Or

samba -V

The previous commands, via displaying a directory containing Samba or information about the installed version of Samba, assure you of the successful installation of Samba on Ubuntu.

To confirm that Samba is running, use the following command:

systemctl status smbd

Displaying the green-texted phrase “Active: active (running)” indicates the active status of the smbd service.

Note: By running the Samba installation command, both the Samba server smbd and the Samba NetBIOS server nmbd are executed. Since you currently do not need nmbd, it is recommended to stop and disable the nmbd service using the following commands to prevent security issues:

sudo systemctl stop nmbd.service

sudo systemctl disable nmbd.service

As a output, the Samba service has been successfully installed and is ready for configuration.

4. Samba Configuration in Linux Ubuntu

To configure Samba, you must navigate to the configuration file of this service, located at /etc/samba/smb.conf. Before making any changes, create a backup of the original configuration file:

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

Next, open the Samba configuration file with your preferred text editor (our preference is to use the Nano editor):

sudo nano /etc/samba/smb.conf

The exquisite art of defining and configuring the Samba server’s behavior can be achieved through the meticulous editing of the esteemed /etc/samba/smb.conf file. This remarkable file is divided into two distinguished sections, namely [global] and [shares]. By skillfully configuring the [global] section, one can effortlessly mold the very essence of the Samba server, encompassing its regal name, noble role, intricate network interfaces, and other captivating details. However, should one aspire to embark upon the noble path of configuring sharing, it is imperative to gracefully edit and configure the illustrious [shares] section.

Let’s start with configuring the Global Settings section, as this allows you to define the behavior of the Samba server.

/etc/samba/smb.conf [global] server string = samba_server server role = standalone server interfaces = lo your_network_interface bind interfaces only = yes disable netbios = yes smb ports = 445 log file = /var/log/samba/smb.log max log size = 10000

  • server string:

Provides necessary information for identifying your server for user connections, such as the server name. server role: Indicates the server type (servers can have various types, including standalone, domain member servers, or domain controllers).

  • interfaces:

Displays the network interface to which the Samba server is connected. bind interfaces only: Ensures Samba’s connection and compliance to the interfaces specified in the interfaces line.

  • disable netbios:

Deactivates NetBIOS functions to facilitate SMB traffic transfer and the server name resolution process.

  • smb ports:

Configures the ports that the Samba server listens to (the default Samba port is port number 445).

  • log file:

Specifies the name and location of the Samba log file.

  • max log size:

Sets the maximum size for the log file in bytes.

 

To change settings in the Samba configuration file, you must uncomment specific settings. For configuring Samba’s Global options, reviewing and modifying key parameters as needed is advisable. These parameters are as follows:

Browsing/Identification:

This section includes parameters like workgroup and server string. You should verify the accuracy of these settings. Ensure that the workgroup setting in your server matches the Windows server with which you intend to share files. Also, confirm the correctness of the server string setting for identifying the Samba server. To configure settings in the Browsing section, simply remove the default values and add the new ones.

Networking:

The network interfaces to which Samba is connected are configurable under the Networking subsection. As mentioned earlier, you need to set the network interface field to the interface to which the Samba server is connected and ensure its correctness. Set the parameter bind interfaces only to yes to ensure that Samba only connects to the interfaces listed in the Samba configuration file. Checking the available interfaces through the following command can be helpful for configuring the Interfaces parameter:

ip link

Debugging:

The parameters log file, max log size, panic action, and logging fall under the Debugging section and should be configured correctly.

Authentication:

The most crucial factor in configuring the Authentication section is the server role parameter, indicating the type of Samba server. Typically, the standalone server value is set for the server role parameter.

Domain: Leave the Domain section unchanged.

Misc: In the Misc section, configure values as follows:

usershare allow guests = yes

Recommendation:

We recommend not altering the global options, and if necessary, you can edit them.

To enhance security regarding logging and user authentication during Samba server configuration, you can modify the default values in the global section. For this purpose, you can add the following expressions to the content of the Samba configuration file to increase the reporting level from the default value of 1. Also, set higher values, such as 5, for passdb and auth debug classes:

log level = 3 passdb:5 auth:5

Then, save the changes and close the file.

After editing the Samba configuration file, you can check for syntax errors by running the Samba utility testparm:

testparm

Output:

Load smb config files from /etc/samba/smb.conf Loaded services file OK. Server role: ROLE_STANDALONE Press enter to see a dump of your service definitions

If the testparm command outputs “Loaded services file OK,” it means there are no syntax errors that would prevent the Samba server from starting. Configuring ubuntu Samba server is enough to configure the Global section, but the configuration of the Samba server doesn’t end here, as its functionality is limited without creating and setting up shares and user accounts.

5. User Account Configuration

Create user accounts authorized for sharing and authenticating with Samba by establishing a home directory for each user. For smoother administrative tasks, opt for Samba directories in /samba/ rather than the standard /home/user. Execute the following commands to create the /samba/ directory at the root of the file system for storing Samba data.

sudo mkdir /samba/

sudo chown :sambashare /samba/

This command creates the /samba/ directory and sets the ownership of the group created when installing samba to sambashare. Then, to create a directory for your desired user, for example, with the name “Amazing,” under the /samba/ directory, execute the following command:

sudo mkdir /samba/ Amazing

After creating the directory, you can add your desired user (in our example, “Amazing”) as a system user using the following command:

sudo adduser –home /samba/Amazing–no-create-home –shell /usr/sbin/nologin –ingroup sambashare Opera

By setting the directory’s permissions to 2770, any file or directory created under /samba/Amazing/ will fall under the group ownership of the parent directory. Consequently, even if an administrator creates a new file in the Amazing user’s directory, the Amazing user retains permission to read and write to that new file.

To grant a user access to the Samba server, add and enable the user on the Samba server. The Samba server on Ubuntu stores user information, including usernames and passwords, in its database, using this data to authenticate logins. Therefore, it’s crucial to add a user to the Samba server. Execute the following commands to accomplish this task:

sudo smbpasswd -a  your_username

sudo smbpasswd -e your_username

6. Configuring Samba Share

Create and configure a share to access files and resources, ensuring Samba is set up correctly. The Samba configuration file (/etc/samba/smb.conf) features distinct sections for each user-dedicated share. Edit the Samba configuration file to add a new section for a user-specific share. To do this, open the Samba configuration file using your preferred text editor (Nano is recommended).

sudo nano /etc/samba/smb.conf

Scroll to the end of the file and add a new section for a simple share to the file content:

[share_name]

comment = My Samba Share

path = /path/to/your/share

browseable = yes

read only = no

writable = yes

guest  ok = no

valid users = your_username

By adding a Samba share configuration block, you have defined specific permissions for your intended user to access a particular share.

share_name: Choose a name for the share that you will use this name when accessing the share.

comment: Provides a description for the share.

path: Specifies the path and location of the sharing directory in the file system.

browseable:

Activates or deactivates the ability of other users to view the share. If set to “yes,” other machines on the network, if aware of the exact name and path of the share, will be able to view it.

read only: This parameter determines whether users are allowed to write to the share or not.

writeable: If this parameter is set to “yes,” it indicates that the user is allowed to read and write to the share.

guest ok: This parameter determines whether guest users have access to the share or not.

valid users: This parameter allows you to specify valid users who have permission to access this share.

After configuring, save and close the file. To ensure the correctness of the configuration, rerun the following command:

testparm

Output:

Load smb config files from /etc/samba/smb.conf Loaded services file OK. Server role: ROLE_STANDALONE Press enter to see a dump of your service definitions

By receiving this output, you can be sure of the Samba configuration.

After ensuring the correct Samba configuration, restart the Samba service for the configuration to take effect:

sudo systemctl restart smbd

7. Adjust Firewall Rules (if necessary)

If you have an active firewall on your Ubuntu system, ensure that Samba traffic is allowed. For example, if you are using the UFW firewall, execute the following commands for this purpose:

sudo ufw allow 139/tcp

sudo ufw allow 445/tcp

sudo ufw allow 137/udp

sudo ufw allow 138/udp

8. Accessing the shared folder from another computer using the Samba server

Connect effortlessly to the Samba server from any computer on the network and put the configured settings to the test. Simply follow the steps outlined below to establish a connection to the Samba share from a different machine.

On Linux through the GUI:

  • To connect to a Ubuntu Samba share from another Ubuntu/Linux machine, open the file manager (e.g., Nautilus) and click the “Other Locations” option.
  • In the address bar, type the following address to connect to the server:

smb://your_ubuntu_server_ip/share_name

Replace your_ubuntu_server_ip with the IP address of your Ubuntu server and share_name with the name of your Samba share.

  • At this step, the Samba username and password that you configured during the setup will be prompted. Type the Credentials information in the respective fields and click the “connect” button.
  • Now, you should be able to access the shared files.

On Linux via the Terminal:

The smbclient command-line tool helps you connect to Samba through the terminal.

1. Installation of smbclient: Therefore, you can install this tool on Linux distributions using your local package manager:

  • For Debian/Ubuntu

sudo apt-get install smbclient

  • For CentOS:

sudo yum install samba-client

  • For Fedora:

sudo samba-client

2. Access the Samba Share: Use the following command to connect to the Samba share:

smbclient //your_ubuntu_server_ip/share_name -U your_username

3. Enter Credentials: If prompted, enter the password for the specified Samba user.

4. Navigate and Interact: As a result, you can access files that have been shared. Use various commands to navigate and interact with the Samba shared in the terminal. For example, the ‘ls‘ command is helpful for listing files, downloading a file, and placing it for upload, etc.

On Windows via GUI:

Accessing a Samba share on the Windows 10 desktop requires navigating to File Explorer. Connect to a Samba share by following these steps:

  • Open File Explorer from the Windows Start menu.
  • Right-click “This PC” in the left-hand menu and select the “Add a network location” option from the opened menu.
  • Click on “Next“.
  • Choose a “Custom network location.”
  • In the address bar, enter the Samba server address and share name as follows and click “Next“:

\\your_ubuntu_server_ip\share_name

Substitute the actual IP address of your Ubuntu server for your_ubuntu_server_ip and the name of the configured Samba share for share_name.

  • Then, enter the Samba username and password that you configured when setting up the Samba user.
  • After authentication, you will be authorized to access the files and shared directories as if you were local.

 

On Windows using Command Prompt:

The’ net use‘ command is used to connect to a Samba share via Command Prompt. For example, after opening the Command Prompt, run the following command:

net use X: \\your_ubuntu_server_ip\share_name /user:your_username

Substitute the IP address of your Ubuntu server for your_ubuntu_server_ip, the name of your Samba share for share_name, and your Samba username for your_username in the command. After executing this command, the system will prompt you to enter the Samba user’s password, allowing you to access the shared file through the mapped drive letter (in this case, X:).

Upon successful execution of the command, you can now access and interact with the Samba share via the command line.

9. Check the Samba logs

To troubleshoot, examine Samba logs and understand the overall configuration in the smb.conf file by executing the following command.

sudo journalctl -xe | grep smbd

Tips for Samba Configuration

Considerations for using Samba to share resources across platforms:

  • Assign a personal file share for each employee.
  • All users should have permission to read and write to the shared file.
  • Each user must own the shared and have no read and write restrictions to their private shared.
Stay Connected on Meta ,X,Instagram .