What is smb.conf File and How to Use It?


  • The smb.conf file is the main configuration file for Samba, allowing file and print sharing between Unix/Linux and Windows systems.
  • It is typically located in the /etc/samba/ directory.
  • The file contains settings divided into sections, such as [global], [homes], [printers], and custom share definitions.
  • To edit the smb.conf file:
    • Open it with a text editor like nano or vi.
    • Make necessary changes to global settings and share definitions.
    • Save the file and exit the editor.
    • Check the configuration for errors using the testparm command.
    • Restart the Samba service using sudo systemctl restart smbd.

What is an smb.conf file?

The smb.conf file is the main configuration file for the Samba suite, which allows for file and print sharing between Unix/Linux and Windows systems. This file contains settings that control the behavior of the Samba server, defining shared resources, permissions, network settings, and more.

Here are some key points about the smb.conf file:

  1. Location: The smb.conf file is typically located in the /etc/samba/ directory on Unix/Linux systems.
  2. Purpose: It defines the configuration settings for the Samba server, including shared resources, authentication, and access control.
  3. Sections: The configuration file is divided into sections, each enclosed in square brackets. The main sections include:
  • [global]: Contains global settings that apply to the entire Samba server.
  • [homes]: Defines the home directory sharing settings for individual users.
  • [printers]: Configures printer sharing options.
  • [sharename]: Defines a specific shared resource, such as a directory or a printer.
  1. Parameters: Within each section, various parameters are used to configure Samba’s behavior. These parameters control aspects such as file permissions, user authentication, logging, and more.
  2. Syntax: The smb.conf file follows a specific syntax, with each parameter and its corresponding value on a separate line. Comments can be added using a semicolon (;) at the beginning of a line.
  3. Reloading Configuration: After making changes to the smb.conf file, the Samba server needs to be restarted or reloaded for the changes to take effect. This can be done using the systemctl restart smbd or systemctl reload smbd command on most Unix/Linux systems.

The smb.conf file plays a crucial role in configuring Samba and enabling seamless file and printer sharing between different operating systems. It allows administrators to customize Samba’s behavior, define shared resources, and enforce access control policies based on their specific requirements.

Example smb.conf File

   workgroup = WORKGROUP
   server string = Samba Server
   netbios name = MYSERVER
   security = user
   log file = /var/log/samba/log.%m
   max log size = 50

   path = /srv/samba/shared
   read only = no
   browseable = yes
   guest ok = yes

Common Tasks

  1. Editing the smb.conf File

Use a text editor like nano or vi to edit the file:

sudo nano /etc/samba/smb.conf
opening samba configuration file in nano editor
  1. Restarting the Samba Service

After making changes, restart the Samba service:

sudo systemctl restart smbd
restarting samba services
  1. Testing the Configuration

Test the configuration for errors:

testing samba configurations

The smb.conf file is highly customizable, allowing you to fine-tune the Samba server to meet specific network and security requirements.

How to Edit the smb.conf File for Samba Server Configuration

The smb.conf file is the main configuration file for the Samba suite, which allows for file and print sharing between Unix/Linux and Windows systems. By editing this file, you can customize your Samba server settings to meet your network and security requirements. Here’s a detailed guide on how to edit the smb.conf file.

Step-by-Step Guide to Edit smb.conf

1. Locate the smb.conf File

The smb.conf file is typically located in the /etc/samba directory. You can verify its location using the following command:

sudo find / -name "smb.conf"
locating smb.conf file

2. Open the smb.conf File in a Text Editor

Use a text editor like nano or vi to open the file. Here’s how to open it with nano:

sudo nano /etc/samba/smb.conf
samba configuration file

3. Make Necessary Changes

Configure your Samba server by editing the following sections:

Global Section

Settings that apply to the entire Samba server are defined under the [global] section. Here’s an example configuration:

   workgroup = WORKGROUP
   server string = Samba Server
   netbios name = MYSERVER
   security = user
   log file = /var/log/samba/log.%m
   max log size = 50
global section changes in config file

Share Definitions

Define shared resources in individual sections. For example, to create a share named shared:

   path = /srv/samba/shared
   read only = no
   browseable = yes
   guest ok = yes
defining shared resources in individual sections

4. Save and Exit

If using nano, save the file by pressing Ctrl+O, then press Enter to confirm. Exit by pressing Ctrl+X.

saving and exiting from configuration file

5. Check the Configuration

Before applying the changes, check the configuration for errors using the following command:


This command will display any syntax errors and allow you to fix them before restarting the service.

testing samba configurations 1

6. Restart the Samba Service

Apply the changes by restarting the Samba service:

sudo systemctl restart smbd

Additional Tips

  • Backup the Configuration: Before making changes, it’s a good practice to back up the original configuration file: sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
  • Documentation: Refer to the Samba documentation for detailed information on each parameter.

By following these steps, you can effectively edit and manage your smb.conf file to configure your Samba server according to your needs.

Here are some common use cases for editing the smb.conf file to configure your Samba server:

Common Use Cases for smb.conf

  1. File Sharing Between Linux/Unix and Windows: Samba enables file sharing between Linux/Unix and Windows systems, allowing users on different platforms to access the same files.
  2. Printer Sharing: Samba can share printers connected to a Linux/Unix system with Windows clients, making it easy to manage print jobs across a network.
  3. Network Browsing: Samba can be configured to make Linux/Unix servers visible in Windows Network Neighborhood, facilitating easy browsing and access to shared resources.
  4. Domain Integration: Samba can integrate with a Windows domain, acting as a domain member server or even as a Primary Domain Controller (PDC) for user authentication and management.
  5. Guest Access: For environments where security is less of a concern, Samba can be configured to allow guest access, enabling users to access shared resources without authentication.
  6. Home Directories: Samba can be configured to provide each user with a personal home directory that is accessible from any networked machine.
  7. Backup Solutions: Samba can be used in backup solutions, allowing backup software running on Windows to access Linux/Unix file systems.

Example Configurations for Common Use Cases

File Sharing

To set up a basic file share:

   path = /srv/samba/shared
   read only = no
   browseable = yes
   guest ok = no

Printer Sharing

To share a printer:

   path = /var/spool/samba
   printable = yes
   guest ok = no
   browseable = no

Network Browsing

To make your server visible in Network Neighborhood:

   workgroup = WORKGROUP
   server string = Samba Server
   netbios name = MYSERVER
   browseable = yes

Domain Integration

To integrate with a Windows domain:

   workgroup = WORKGROUP
   security = ads
   realm = YOUR.REALM
   password server = your.domain.controller

Guest Access

To allow guest access:

   path = /srv/samba/public
   public = yes
   only guest = yes
   writable = yes
   printable = no

Home Directories

To provide home directories for users:

   comment = Home Directories
   browseable = no
   writable = yes

How To Configure smb.conf

For more advanced setups, the smb.conf file offers numerous options to fine-tune and optimize your Samba server. These configurations can enhance performance, security, and functionality. Here’s a comprehensive guide on advanced configuration and optimization.

1. Performance Tuning

Optimize Samba for better performance by adjusting various parameters:

   socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192
   read raw = yes
   write raw = yes
   max xmit = 65535
   dead time = 15
   getwd cache = yes

2. Security Enhancements

Enhance security by enforcing stricter authentication and access controls:

   encrypt passwords = yes
   smb passwd file = /etc/samba/smbpasswd
   passdb backend = tdbsam
   security = user
   map to guest = Bad User

3. Logging and Auditing

Configure detailed logging and auditing to monitor Samba activities:

   log level = 2
   log file = /var/log/samba/log.%m
   max log size = 1000
   syslog = 0

4. Share-Level Settings

Advanced share settings for specific use cases:

   path = /srv/samba/shared
   read only = no
   browseable = yes
   guest ok = no
   veto files = /*.exe/*.com/*.dll/
   delete veto files = yes

5. Domain Controller Configuration

Set up Samba as a Primary Domain Controller (PDC):

   domain logons = yes
   logon path = \\%N\profiles\%U
   logon drive = H:
   logon home = \\%N\%U
   domain master = yes
   local master = yes
   preferred master = yes
   os level = 65

   path = /srv/samba/netlogon
   read only = no
   browseable = no

   path = /srv/samba/profiles
   read only = no
   create mask = 0600
   directory mask = 0700

How To Optimize smb.conf?

1. Use of Tuning Parameters

Adjust tuning parameters to improve performance:

   aio read size = 16384
   aio write size = 16384
   aio write behind = true
   min receivefile size = 16384

2. Network Optimization

Optimize network settings for better throughput:

   use sendfile = yes
   large readwrite = yes
   getwd cache = yes

3. File System Tuning

Ensure the underlying file system is optimized for Samba workloads:

   write cache size = 262144
   strict locking = no
   strict sync = no
   sync always = no

Tools and Utilities for Managing Samba

In addition to the smb.conf file, several tools and utilities can help you manage and troubleshoot your Samba server. These tools offer various functionalities, from configuration and monitoring to user management and testing. Here are some essential tools and utilities for Samba management:

1. smbstatus

The smbstatus utility provides information about current Samba connections, open files, and locked files. It is useful for monitoring active sessions and diagnosing issues.

sudo smbstatus
checking current samba connections

2. smbpasswd

The smbpasswd utility is used for managing user passwords in the Samba password database. It allows you to add, delete, and change user passwords.

# Add a new user
sudo smbpasswd -a username

# Change a user's password
sudo smbpasswd username

# Delete a user
sudo smbpasswd -x username
modifying samba users account

3. testparm

The testparm utility checks the syntax of your smb.conf file and reports any errors. It is useful for validating changes before restarting the Samba service.

sudo testparm

4. pdbedit

The pdbedit utility manages the Samba user database. It allows you to list, add, modify, and delete user accounts in the Samba password database.

# List all Samba users
sudo pdbedit -L

# Add a new user
sudo pdbedit -a username

# Modify a user account
sudo pdbedit -r username

# Delete a user account
sudo pdbedit -x username
listing all samba users

5. smbclient

The smbclient utility is a command-line tool similar to FTP for accessing SMB/CIFS resources on a network. It allows you to interact with Samba shares from the command line.

# Connect to a Samba share
smbclient //servername/sharename -U username

# List files in the share
smb: \> ls

# Download a file
smb: \> get filename

# Upload a file
smb: \> put filename

Monitoring and Logging Tools

1. Log Files

Samba logs various events and errors to log files located in /var/log/samba/. These logs are crucial for troubleshooting and monitoring the server’s activities.

# View Samba log files
sudo tail -f /var/log/samba/log.smbd
sudo tail -f /var/log/samba/log.nmbd

2. SWAT (Samba Web Administration Tool)

SWAT is a web-based interface for configuring Samba. Although it is not as commonly used today, it can still be helpful for those who prefer a graphical interface for Samba management.

# Install SWAT
sudo apt-get install swat

# Access SWAT in a web browser

Final Thoughts

I’ve covered everything in this post about setting up, optimizing, and managing your smb.conf file. You now know how to configure the global settings and share definitions, edit the file with nano or vi, and restart your Samba service. These steps will help you get your Samba server running smoothly, meeting both your network and security needs.

If you want to explore more, check out these articles:

Frequently Asked Questions

What is the purpose of the smb.conf file in Samba?

The smb.conf file is the main configuration file for Samba, a suite of programs that allows for file and print sharing between Unix/Linux and Windows systems. This file contains various settings that control the behavior of the Samba server, including defining shared resources, permissions, network settings, and security configurations.

Where is the smb.conf file typically located?

The smb.conf file is usually found in the /etc/samba/ directory. You can verify its location on your system by using the command sudo find / -name "smb.conf" to search for the file.

How do I open and edit the smb.conf file?

You can open and edit the smb.conf file using a text editor like nano or vi. For example, to open it with nano, use the command sudo nano /etc/samba/smb.conf. Make your changes and save the file to apply the new configurations.

What is the [global] section in smb.conf?

The [global] section in smb.conf contains settings that apply to the entire Samba server. These settings include parameters like the workgroup name, server description, NetBIOS name, security mode, and logging options.

How do I define a shared directory in smb.conf?

To define a shared directory, create a new section in smb.conf with the share name in square brackets. Specify the path to the directory and set additional options like read/write permissions. For example:

[shared] path = /srv/samba/shared read only = no browseable = yes

How can I secure my Samba shares using smb.conf?

You can secure Samba shares by setting the security parameter to user in the [global] section and specifying valid users for each share. Use options like valid users, guest ok = no, and encrypt passwords = yes to enforce authentication and restrict access.

What does the workgroup parameter do in smb.conf?

The workgroup parameter specifies the name of the workgroup that the Samba server will join. This is important for network browsing and integration with Windows networks, where all systems must be in the same workgroup to share resources.

How do I allow guest access to a Samba share?

To allow guest access, set the guest ok parameter to yes in the share definition. You may also need to set map to guest = Bad User in the [global] section to ensure users without a Samba account are mapped to the guest account.

How can I make a Samba share invisible to network browsers?

To make a Samba share invisible in network browsers, set the browseable parameter to no in the share definition. This will hide the share from network neighborhood views, but it will still be accessible if the user knows the share name.

What is the purpose of the log file parameter in smb.conf?

The log file parameter specifies the path to the log file where Samba will record server events and errors. This is useful for troubleshooting and monitoring the server’s activity. For example, log file = /var/log/samba/log.%m creates a separate log file for each client machine.

How do I restrict access to a Samba share to specific users?

To restrict access to specific users, use the valid users parameter in the share definition. List the usernames allowed to access the share. For example:

[shared]path = /srv/samba/shared
valid users = user1, user2
read only = no

What does the netbios name parameter do?

The netbios name parameter sets the NetBIOS name of the Samba server, which is the name by which the server will be identified on the network. If not set, the server uses the hostname by default.

How do I configure Samba to act as a Primary Domain Controller (PDC)?

To configure Samba as a PDC, set parameters like domain logons = yes, logon path, logon drive, and domain master = yes in the [global] section. You will also need to define shares for netlogon and profiles.

How can I enforce password encryption in Samba?

To enforce password encryption, set encrypt passwords = yes in the [global] section. This ensures that passwords are encrypted when transmitted over the network, enhancing security.

What is the socket options parameter used for?

The socket options parameter is used to optimize the performance of the Samba server by setting TCP/IP socket options. Common settings include TCP_NODELAY and SO_RCVBUF=8192 SO_SNDBUF=8192 to improve network performance.

How do I enable detailed logging in Samba?

To enable detailed logging, increase the log level parameter in the [global] section. A higher log level provides more detailed information but can generate large log files. For example, log level = 2 provides general logging, while higher levels offer more verbosity.

How do I test my smb.conf configuration for errors?

Use the testparm utility to check your smb.conf file for syntax errors and potential issues. Run the command sudo testparm after editing the file. This tool will highlight any errors and help you ensure your configuration is valid.

What is the veto files parameter?

The veto files parameter allows you to specify patterns for files and directories that should be hidden or inaccessible in a share. For example, veto files = /*.exe/*.dll/ hides all executable and DLL files from the share.

How do I manage user accounts in Samba?

You can manage user accounts using the smbpasswd utility for adding, deleting, and changing passwords. Additionally, the pdbedit tool provides more advanced management of user accounts in the Samba password database.

What is the dead time parameter?

The dead time parameter specifies the number of minutes a connection must be idle before it is closed by the server. Setting this parameter helps to free up resources on the server. For example, dead time = 15 will close idle connections after 15 minutes.

Which command can be used to connect to check the /etc/samba/smb.conf file for syntax errors?

To check the /etc/samba/smb.conf file for syntax errors, you can use the testparm command. This command will parse the smb.conf file and report any syntax errors or potential issues it finds. It helps validate the configuration before restarting the Samba service to apply the changes.



Ojash is a skilled Linux expert and tech writer with over a decade of experience. He has extensive knowledge of Linux's file system, command-line interface, and software installations. Ojash is also an expert in shell scripting and automation, with experience in Bash, Python, and Perl. He has published numerous articles on Linux in various online publications, making him a valuable resource for both seasoned Linux users and beginners. Ojash is also an active member of the Linux community and participates in Linux forums.



Akshat is a software engineer, product designer and the co-founder of Scrutify. He's an experienced Linux professional and the senior editor of this blog. He is also an open-source contributor to many projects on Github and has written several technical guides on Linux. Apart from that, he’s also actively sharing his ideas and tutorials on Medium and Attirer. As the editor of this blog, Akshat brings his wealth of knowledge and experience to provide readers with valuable insights and advice on a wide range of Linux-related topics.

Share this article
Shareable URL
Prev Post

How to Encrypt Files in Linux? [6 Best Methods]

Leave a Reply

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

Read next