Samba Server   «Prev  Next»

Lesson 3 Installing and configuring a Samba server
ObjectiveInstall and configure a Samba server.

Installing and Configuring a Samba Server

You can install Samba either automatically or manually using Red Hat Linux. During installation, select DOS/Windows Connectivity to automatically install the Samba RPMs[1] . If you do not select this option, you can install them manually with the following RPMs:
  1. samba-(version).(arch).rpm
  2. samba-client-(version).(arch).rpm
  3. samba-common-(version).(arch).rpm

You will need to replace (version) and (arch) with the latest version and architecture, respectively, from your Red Hat Linux CD-ROM. For example, the 2.0.7 Intel RPMs are samba-2.0.7.i386.rpm, samba-client-2.0.7.i386.rpm, and samba-common-2.0.7.i386.rpm
.

Configuring Samba

Once Samba is installed, you must configure it to your needs. To tailor Samba to your specifications, you will need to modify two major sections of /etc/smb.conf, the Samba configuration file. The first, called "global shares," affects Samba's overall behavior. The second, called simply "shares," affects only specific shared resources. To familiarize yourself with Samba's configuration file, roll your mouse over the highlighted lines to see explanations for each main section of the file.
Samba Configuration File
  1. Every share's configuration begins with a string enclosed in square brackets. In this case, the global share's configuration follows [global]
  2. These are the global configuration options, specified using name = value syntax. Samba will set the given name's value to whatever follows the equal sign. Comment lines begin with a semi-colon(;) or a hash (#)
  3. Every share's configuration begins with a string enclosed in square brackets. In this case the home share's configuration follows [homes].
  4. These are the home share's configuration options, specified using name=value syntax. Samba will set the given name's value to whatever follows the equal sign. Comment lines begin with a semi-colon(;) or a hash #

Steps for installing and Configuring Samba Server on Red Hat Linux

To install and configure a Samba server on Red Hat Enterprise Linux (RHEL) 9.2, follow these steps:
  1. Install Samba Packages
    1. Open a terminal and ensure your system is updated:
              sudo dnf update -y
              
    2. Install the Samba server package:
              sudo dnf install samba samba-common samba-client -y
              
  2. Start and Enable Samba Services
    1. Enable and start the Samba services:
              sudo systemctl enable smb
              sudo systemctl enable nmb
              sudo systemctl start smb
              sudo systemctl start nmb
              
    2. Verify the services are running:
              sudo systemctl status smb
              sudo systemctl status nmb
              
  3. Configure the Samba Configuration File
    1. Open the Samba configuration file with a text editor:
              sudo nano /etc/samba/smb.conf
              
    2. Make necessary modifications for your Samba setup. For example, to share a directory (`/srv/samba/share`): Add this to the configuration file:
              [global]
              workgroup = WORKGROUP
              security = user
              map to guest = Bad User
              dns proxy = no
      
              [ShareName]
              path = /srv/samba/share
              browsable = yes
              writable = yes
              guest ok = yes
              read only = no
              
    3. Save and close the file (`CTRL+O`, `CTRL+X`).
  4. Create the Shared Directory
    1. Create the shared directory:
              sudo mkdir -p /srv/samba/share
              
    2. Set appropriate permissions:
              sudo chmod -R 0777 /srv/samba/share
              sudo chown -R nobody:nobody /srv/samba/share
              
  5. Add a Samba User
    1. If you want authenticated access, add a Linux user:
              sudo useradd -M -s /sbin/nologin sambauser
              
    2. Set the Samba password for the user:
              sudo smbpasswd -a sambauser
              
    3. Enable the user:
              sudo smbpasswd -e sambauser
              
  6. Adjust Firewall Settings
    1. Allow Samba services through the firewall:
         sudo firewall-cmd --permanent --add-service=samba
         sudo firewall-cmd --reload
         
  7. Test the Samba Configuration
    1. Test the Samba configuration for errors:
              sudo testparm
              
    2. If no errors are reported, proceed to the next step.
  8. Access the Samba Share
    • From a Windows Client
      • Open File Explorer and enter: `\\\ShareName`
      • Provide authentication if required.
    • From a Linux Client
      • Install Samba client tools:
                        sudo dnf install cifs-utils -y
                        
      • Mount the share:
                        sudo mount -t cifs -o username=sambauser,password= //Samba_Server_IP/ShareName /mnt
                        
  9. Monitor Samba Logs - To troubleshoot issues, check Samba logs:
      sudo tail -f /var/log/samba/log.smbd
      sudo tail -f /var/log/samba/log.nmbd
      

Additional Notes:
  • Replace `` with the IP address of your Samba server.
  • Always use strong passwords for Samba users.
  • Consider restricting access to the Samba share by specifying allowed IP ranges in the `[ShareName]` section:
  hosts allow = 192.168.1.0/24
  

Some configuration options can appear in both the global and the specific share sections. When options appear in the global section, the option affects the entire program. When options appear in a specific share section, the option affects only that shared resource. Because Samba provides many configuration choices, you should read the entire smb.conf man page before modifying the default configuration. In the next lesson, you will learn about shares, homes, and printing.

[1] RPM: An acronym for Red Hat Package Manager, RPMS is a standard source and binary distribution format.

SEMrush Software 3 SEMrush Banner 3