Setting Up an SMB Server for Media Sharing on Ubuntu | Generated by AI

Home PDF

Here’s a step-by-step guide to setting up an SMB (Server Message Block) server on Ubuntu to serve media files. SMB is a protocol that allows you to share files across a network, making it ideal for serving media to devices like computers, TVs, or mobile devices. We’ll use Samba, the software that provides SMB functionality on Linux, and configure it to share a directory containing your media files.


Step 1: Install Samba

First, you need to install Samba on your Ubuntu system. Open a terminal and run the following commands:

sudo apt update
sudo apt install samba

Step 2: Back Up the Samba Configuration File

Before making changes, it’s a good practice to back up the default Samba configuration file. Run:

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

This creates a copy of the original file (smb.conf.backup) in case you need to revert changes later.


Step 3: Configure the Media Share

The Samba configuration file is located at /etc/samba/smb.conf. You’ll edit this file to define a share for your media files. For this example, assume your media files are stored in /home/user/media (replace user with your actual username).

  1. Open the configuration file in a text editor, such as nano:
    sudo nano /etc/samba/smb.conf
    
  2. Scroll to the bottom of the file and add the following section:
    [media]
        path = /home/user/media
        browseable = yes
        read only = yes
        guest ok = yes
    
  3. Save and exit:
    • In nano, press Ctrl+O, then Enter to save, and Ctrl+X to exit.

Explanation of the Configuration:


Step 4: Verify the Configuration

To ensure there are no syntax errors in your configuration, run:

testparm

This command checks the smb.conf file and displays the loaded services. If there are no errors, you’re good to proceed.


Step 5: Restart Samba Services

Samba runs two services: smbd (handles file sharing) and nmbd (handles network discovery). Restart them to apply your changes:

sudo systemctl restart smbd
sudo systemctl restart nmbd

To ensure these services start automatically on boot (usually enabled by default), you can run:

sudo systemctl enable smbd
sudo systemctl enable nmbd

Step 6: Adjust File Permissions

For guest access to work, the media directory and its files must be readable by everyone. Set the appropriate permissions with:

sudo chmod -R 755 /home/user/media

Step 7: Configure the Firewall

If Ubuntu’s firewall (UFW) is active, you need to allow SMB traffic. First, check the firewall status:

sudo ufw status

If it’s active, open the necessary ports:

sudo ufw allow 139/tcp
sudo ufw allow 445/tcp
sudo ufw allow 137/udp
sudo ufw allow 138/udp

Reload the firewall to apply the changes:

sudo ufw reload

If the firewall is inactive, you can skip this step.


Step 8: Test the SMB Share

Your SMB server should now be running. To test it:

  1. Find your Ubuntu machine’s IP address:
    ip addr show
    

    Look for the IP address (e.g., 192.168.1.100) under your network interface (like eth0 or wlan0).

  2. From another device on the network (e.g., a Windows PC):
    • Open File Explorer and enter: \\<ubuntu-ip-address>\media (e.g., \\192.168.1.100\media).
    • You should see your media files. Since guest access is enabled, no login is required.

Troubleshooting Tips

If you encounter issues:


Summary of Commands

Here’s the complete sequence:

sudo apt update
sudo apt install samba
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.backup
sudo nano /etc/samba/smb.conf  # Add the [media] section
testparm
sudo systemctl restart smbd
sudo systemctl restart nmbd
sudo chmod -R 755 /home/user/media
sudo ufw allow 139/tcp
sudo ufw allow 445/tcp
sudo ufw allow 137/udp
sudo ufw allow 138/udp
sudo ufw reload

Your SMB server is now set up to serve media files from /home/user/media! Access it from any device on your network using the IP address and share name (\\<ip-address>\media).


Back 2025.03.16 Donate