What is Samba server in Linux

what is samba server in linux?

Introduction

Samba has been around since the 1990s and is still used actively today. It plays an important role when different operating systems have to work together in a shared network environment.

Well, it makes it possible for Linux systems to talk with Windows systems over a network. That is, Windows users can access Linux resources as if they were native to Windows. 

Moreover, Samba uses a standard protocol called SMB (Server Message Block) for file and printer sharing in Windows environments. This capability is especially useful in organisations where both Linux and Windows machines are used side by side.

This blog will discuss Samba in depth.

What is Samba Server in Linux?

On a Linux system, the Samba server becomes a useful open-source tool for sharing files or printers with a Windows machine. It helps Linux and Windows systems communicate on the same network. In fact, Samba acts like a translator between the two systems as it enables both systems to exchange files, printers, and other shared resources easily.

So, when someone asks, “What is a Samba server in Linux?” The simple answer is – A software suite with which Linux servers can share files, printers, etc with Windows systems using the SMB protocol.

Why is Samba important?

Here are a few points that help explain this:

  • File Sharing Across OS

The most common use of Samba is to share a folder on a Linux system so that Windows users on the same network can access those files. You can set permissions to allow either read-only or read-write access depending on your needs.

Thus, you can share a directory or file from a Linux machine and let Windows users access it as if it were a shared Windows folder.

  • Access SMB Shares from Linux

Not only can Linux share files with Windows, but it can also connect to shared folders hosted on Windows servers. This helps users access all types of resources across the network using a simple mount command or a GUI file manager.

  • Printer Access Between Systems

You don’t need to plug printers into every Windows system connected to your Linux server. Many can use that printer.

Moreover, just like files and folders, you can also access printers that are shared from Windows machines. Samba makes the connection process easier by managing the protocols involved in the background.

  • Support for Authentication and Permissions

Samba supports user accounts and password protection. This helps system admins manage access control with both public and private shares without needing separate setups for Linux and Windows.

  • Windows Client Integration

You can even join Windows machines to a Samba-based domain. So, you can enable network-wide user management. 

  • Act as a Domain Controller

In more advanced use cases, Samba can act as a domain controller for a network, just like Windows Server does. In other words, you can set access and login controls and manage permissions for the resources.

  • Blended Network Environments

Many offices use both Linux and Windows machines. Samba – a reliable and open source, with strong community support – makes it easier to have a smooth connection and shared workflow.

How Samba Works in a Linux System

Samba comes with several services and configuration files that work together.

To make it simple, here’s how Samba operates in a Linux environment:

Samba makes use of two main services — smbd and nmbd.

  • smbd handles all file and printer sharing functions. That is, the users on Windows can connect to Linux’s shared folders and printers.
  • nmbd handles NetBIOS name resolution and browsing support. This means it helps Linux machines appear in Windows’ network places.

These two services together form the heart of a Samba server setup. When installed properly, Linux acts like a Windows file server.

The Core Components of Samba You Should Know

What is Samba in Linux, as per its core component?

  1. smb.conf

This is the main configuration file. Mostly, its location is at /etc/samba/smb.conf. You define everything here, such as what folders to share, who can access them, what permissions to give, and more. 

  2. Samba Users

Samba users must be mapped to existing Linux users. You might need to create Samba-only users. For that, authentication is handled separately using smbpasswd

  3. Samba Groups

Create user groups. They help in controlling access to shared folders more easily in larger environments.

  4. Service Daemons (smbd and nmbd)

These run in the background. You can control them using systemctl or service commands like start/stop, and enable them at boot.

  5. Firewall Rules

Samba uses specific ports. Your shares won’t be accessible if they are blocked. You have to allow the right TCP ports like 137, 138, 139, and 445.

How to Install Samba Server on Linux

Most Linux distributions already have Samba available in their official package repositories. You just need to install it using your package manager.

Step-by-Step Installation Guide

  • For Ubuntu or Debian-based systems:

Open your terminal and run:

sudo apt update

sudo apt install samba

  • For RHEL, CentOS, or Fedora:

sudo dnf install samba samba-client samba-common

After the installation finishes, you can check the version to confirm it is installed:

smbd –version

This command will show the installed Samba version, meaning the setup was successful.

Note: Always update your system before installing new packages to avoid dependency issues.

How to Configure Samba on Linux

The next step after installation is to configure it to share folders or files. All Samba configurations are stored in a file called smb.conf. The location is /etc/samba/smb.conf.

Let’s go step-by-step to set up a basic shared folder.

  1. Create a Folder to Share

Let’s say you want to share a folder called shared_folder:

sudo mkdir -p /srv/samba/shared_folder

sudo chmod 2775 /srv/samba/shared_folder

sudo chown nobody:nogroup /srv/samba/shared_folder  # for guest access

  2. Edit the Samba Configuration File

Open and edit the file smb.conf in an editor –

sudo nano /etc/samba/smb.conf

Scroll to the bottom and add this section:

[SharedFolder]

   path = /srv/samba/shared_folder

   browsable = yes

   read only = no

   guest ok = yes

Note: This setup allows guest access. For more secure setups, you should define valid users and disable guest access.

  3. Restart Samba Services

After saving the changes to the config file, restart the Samba services:

sudo systemctl restart smbd

sudo systemctl enable smbd

  4. Allow Samba Through the Firewall (If Enabled)

Ensure your Linux machine is ready to share the folder over the network with the below.

sudo ufw allow ‘Samba’

  5. Access the Share from Windows

On your Windows machine, open File Explorer.

In the address bar, type:

\\<IP address of Linux machine>\SharedFolder

 Example:

\\192.168.1.100\SharedFolder

How to Add and Manage Samba Users

By default, the configurations give access as a guest (no login) or as authenticated users. Let’s see how to add a Samba user and manage their access.

  1. Add a Linux System User

Each Samba user must first exist as a Linux system user. That is, each Samba user must have a corresponding Linux system account to authenticate and access files. If the user doesn’t exist, create with –

sudo adduser sambauser

You will be asked for your password and other information. You can skip the extra details and just press Enter for those.

  2. Add the User to Samba

Now, link the Linux user to Samba by setting a Samba password:

sudo smbpasswd -a sambauser

You will be asked to set a password for Samba that could be different from the one of the Linux system.

To enable the account in Samba:

sudo smbpasswd -e sambauser

Note: You can use any existing Linux user, but you need to set a Samba password for them.

  3. Edit Samba Configuration for Secure Access

Modify the shared folder setup for secure access.

Open the Samba config file:

sudo nano /etc/samba/smb.conf

Find the shared folder section you added earlier, and change it like this:

[SecureShare]

   path = /srv/samba/shared_folder

   valid users = sambauser

   guest ok = no

   writable = yes

   browsable = yes

This tells Samba:

  • Only the user sambauser can access it
  • Guest users are not allowed
  • The user can read and write files

Save and exit the file.

  4. Restart Samba to Apply Changes

sudo systemctl restart smbd

  5. Test the Connection from Windows

On a Windows computer, go to File Explorer > Enter the IP address of your Linux machine as below –

\\192.168.1.100\SecureShare

Type your username – password (the ones you made for Samba earlier).

Managing Samba Users

Here are some useful commands to manage Samba users:

Task Command
Add user sudo smbpasswd -a username
Enable user sudo smbpasswd -e username
Disable user sudo smbpasswd -d username
Delete the Samba user sudo smbpasswd -x username

Advanced Samba Sharing Options

Get more control over who can do what with your shared folders with the below options –

  1. Read-Only Share (No File Changes Allowed)

Users can only view files with the below. They cannot edit or delete them:

[ReadOnlyShare]

   path = /srv/samba/readonly

   valid users = sambauser

   read only = yes

   guest ok = no

   browsable = yes

Note: Make sure the folder /srv/samba/readonly exists and is readable by the user.

Set correct permissions (Ensure correct folder ownership and permissions for read-only access:)

sudo mkdir -p /srv/samba/readonly

sudo chown -R root:sambauser /srv/samba/readonly

sudo chmod -R 755 /srv/samba/readonly

  2. Group-Based Access

Control access as per the Linux groups –

Step 1 – Create a group

sudo groupadd sambashare

Step 2 – Add users

sudo usermod -aG sambashare sambauser

Step 3 – Folder permissions

sudo mkdir -p /srv/samba/groupfolder

sudo chown -R :sambashare /srv/samba/groupfolder

sudo chmod -R 770 /srv/samba/groupfolder

Step 4 – Group access configuration

[GroupShare]

   path = /srv/samba/groupfolder

   valid users = @sambashare

   writable = yes

   guest ok = no

   browsable = yes

  • Restart command for Samba:

sudo systemctl restart smbd

  3. Separate Permissions User-wise

With the below command, 

  • user1 → read and write both
  • user2 → read only

[MixedAccess]

   path = /srv/samba/mixed

   valid users = user1 user2

   read list = user2

   write list = user1

   guest ok = no

   browsable = yes

  4. Hide Files or Folders

To hide specific files:

  hide files = /secret.txt/*.bak/

To prevent access (not just hiding):

  veto files = /secret.txt/*.bak/

   delete veto files = yes

Conclusion

So, what is the Samba server in Linux? To summarize, it is a practical way to share files across different operating systems, including Windows and Linux. It combines simplicity with robust configuration options for secure and flexible file sharing. 

With just a few commands and configuration edits, you can create secure, flexible shared folders for personal or multi-user access. 

Deploy a Samba server for file sharing or seamless Linux-Windows integration with Cantech. We provide all types of server hosting to support your specific setup needs. Contact us now!

FAQs

What is a Samba server used for?

The open-source software suite called Samba helps you share files, printers, etc over a network between Linux and Windows systems. Thus, it enables smooth communication and resource sharing between different operating systems.

Why is Samba used?

Samba is useful for sharing files in multiple OS environments. That is, it helps Linux servers function as file and print servers that are accessible from Windows clients.

What does Samba mean in Linux?

In Linux, as an open-source software suite, Samba enables resource sharing and domain control functionalities with the SMB protocol.

What is the difference between FTP and Samba server?

FTP is a protocol used for file transfers between systems, mostly using the Internet. Whereas, you can use Samba to seamlessly share files and printers between Linux and Windows machines within local networks.

Which is better, Samba or FTP?

It depends on the use case. Samba is better for real-time local file sharing and network drives. On the other hand, FTP is used for uploading and downloading files over long distances or remote servers.

samba server

samba server in linux

what is samba server?

About the Author
Posted by Bansi Shah

Through my SEO-focused writing, I wish to make complex topics easy to understand, informative, and effective. Also, I aim to make a difference and spark thoughtful conversation with a creative and technical approach. I have rich experience in various content types for technology, fintech, education, and more. I seek to inspire readers to explore and understand these dynamic fields.

Drive Growth and Success with Our VPS Server Starting at just ₹ 599/Mo