The Tech Pulse

The Tech Pulse

Ubuntu Server - Network Storage with Samba

Network Storage with Samba on Your $0 Home Server

With Samba, you can easily set up shared network storage that is accessible by all devices in your home, including Windows, macOS, and Linux systems. Samba is an open-source implementation of the SMB/CIFS protocol, the same protocol used by Windows file sharing. This means your server can act as a file server, providing a shared drive for your home network.

Here’s a detailed guide on how to configure Samba for your home server.


Why Use Samba for Network Storage?

  • Centralized file storage: Keep your files in one place, accessible from any device on your network.
  • Cross-platform compatibility: Works with Windows, macOS, Linux, and even mobile devices.
  • Automatic backups: Use it to store backups from multiple computers or devices.
  • Media hosting: Combine with Jellyfin to store and serve videos and music directly from your shared folders.

Step-by-Step Samba Setup on Your Home Server

1. Install Samba on Ubuntu Server

Samba is included in the Ubuntu repositories, making installation simple.

  1. SSH into your server and run:

    sudo apt update sudo apt install samba
  2. After installation, check the Samba version to ensure it’s installed correctly:

    sudo smbstatus

    If Samba is installed, this command will display the current status.


2. Create a Shared Directory

  1. Choose a location for your shared files. For example:

    sudo mkdir -p /media/myfiles
  2. Change the ownership and permissions of the directory to make it accessible:

    sudo chown $USER: /media/myfiles sudo chmod 775 /media/myfiles
    • chown: Makes the current user the owner of the directory.
    • chmod 775: Ensures the owner has read, write, and execute permissions.

3. Configure Samba for Network Sharing

  1. Open the Samba configuration file with a text editor:

    sudo nano /etc/samba/smb.conf
  2. Find the line:

    map to guest = bad user
    

    Change it to:

    map to guest = never
    

    This ensures users are required to authenticate with valid credentials.

  3. Add a new shared folder configuration at the end of the file:

    [MyFiles]
    path = /media/myfiles
    browseable = yes
    writable = yes
    valid users = [your-username]
    read only = no
    create mask = 0755
    
    • path: The directory you created for shared storage.
    • browseable: Makes the share visible to network users.
    • valid users: List the usernames that can access the share.
    • create mask: Ensures files are created with the correct permissions.
  4. Save the file by pressing Ctrl + X, then Y, and Enter.


4. Create a Samba User

To access the shared folder, you need a Samba user with a password.

  1. Create a Samba password for your existing user:
    sudo smbpasswd -a $USER
    You’ll be prompted to enter and confirm the password.

5. Restart the Samba Service

To apply the changes, restart Samba:

sudo systemctl restart smbd

6. Access Your Shared Folder from Other Devices

Windows

  1. Open File Explorer and click This PC.
  2. Select Map network drive from the toolbar.
  3. In the Folder field, enter the server’s IP address:
    \\[server-ip]\MyFiles
    
  4. Check Reconnect at sign-in if you want it to reconnect on startup.
  5. Enter the Samba username and password you set earlier.
  6. The shared folder will now appear as a network drive.

macOS

  1. Open Finder and click Go > Connect to Server from the top menu.
  2. Enter:
    smb://[server-ip]/MyFiles
    
  3. Click Connect and enter the Samba credentials when prompted.
  4. The shared folder will mount like any other drive on your Mac.

Linux

  1. Open a file manager (like Nautilus).
  2. Press Ctrl + L to open the location bar.
  3. Enter:
    smb://[server-ip]/MyFiles
    
  4. Click Connect and enter your Samba credentials.

7. Make the Shared Folder Auto-Mount on Reboot (Optional)

To automatically mount the shared folder on Linux clients:

  1. Open the terminal and edit the fstab file:

    sudo nano /etc/fstab
  2. Add the following line at the end:

    //server-ip/MyFiles /mnt/myfiles cifs username=[your-username],password=[your-password],iocharset=utf8,vers=3.0 0 0
    
  3. Create the mount point:

    sudo mkdir -p /mnt/myfiles
  4. Mount the shared folder:

    sudo mount -a

This ensures the shared folder is mounted every time the computer reboots.


8. Troubleshooting Tips

  • Connection errors? Make sure the firewall on your server allows Samba traffic:

    sudo ufw allow samba
  • Check the Samba service status:

    sudo systemctl status smbd
  • Verify the shared folder:

    testparm

    This checks the Samba configuration for syntax errors.

  • Permissions issues? Ensure your shared folder permissions are correct:

    sudo chmod -R 775 /media/myfiles

9. Using the Shared Folder for Backups and Media

  • Backups: Use tools like Time Machine (on macOS) or Windows Backup to store backups in the shared folder.
  • Media Hosting: Store media files (movies, music, etc.) in the shared folder and use Jellyfin to serve them to other devices.
  • Collaborative Storage: Share the folder with family members, with each user having their own sub-directory.

Summary

With Samba, your $0 Home Server becomes a centralized file server for your entire network. It works seamlessly across Windows, macOS, and Linux devices, allowing you to store, access, and back up files easily. This setup is perfect for network storage, media hosting, and collaborative file sharing without needing expensive NAS devices or cloud subscriptions.

By following these steps, you now have a fully functional network drive that can be accessed by all devices in your home.