Create a Samba network share

Create a Samba network share

Create a network share using Samba on Ubuntu

Last updated:

linux nas ubuntu

Overview

Samba, using the SMB protocol, allows you to share your files and folders with other clients. This article will show you how to create and configure such a share.

Install Samba

First we need to install Samba.

sudo apt-get update
sudo apt install samba

Now we can make sure Samba is installed by checking its status.

sudo smbstatus -V
Version 4.19.5-Ubuntu

Prepare files and folders

I have a folder I would like to share, being /DUMPSTER/myshare. I need to check the permissions on this folder.

ls -ld /DUMPSTER/myshare
drwxr-xr-x 2 dave dave 3 Apr  8 22:10 /DUMPSTER/myshare

This tells us that the user dave has read/write/execute (rwx) permission, the group dave has read/execute (r-x) permission, and that everyone else has read/execute (r-x) permission.

Create a user

I want the user dave to have access to the share from another computer.

We have to add our user to the Samba database and set a password.

sudo smbpasswd -a dave

We will need this username and password to access our Samba share.

Create the Samba share

The configuration file for Samba is located at /etc/samba/smb.conf. To add our directory /DUMPSTER/myshare, we need to edit the configuration file.

sudo nano /etc/samba/smb.conf

Lets add the following to the bottom of the configuration file.

[sambashare]
    comment = My samba share
    path = /DUMPSTER/myshare
    read only = no
    browsable = yes
    guest ok = no

We have labeled this section sambashare

So any clients will connect to it using this label, for example, 192.168.1.234/sambashare

Make sure you restart Samaba after making these changes.

sudo service smbd restart

The user dave has read/write/execute permission on the directory myshare so will have full access. As you can see guest ok is set to no, so any user without valid permissions will not be able to access the share.

Finally update the firewall rules to allow Samba traffic.

sudo ufw allow samba
Rules updated
Rules updated (v6)

Guest share

A guest share is available to users without a valid username or password. Such a user will be given access to the share with the guest username set it the Samba configuration file. The default setting for this is nobody.

sudo nano /etc/samba/smb.conf

Then in our new sambashare section, change guest ok to yes.

guest ok = yes

Then restart Samaba.

sudo service smbd restart

The directory myshare has read/execute permissions set on it for everyone else, so these would be the permissions granted to any guest user.

Check that it worked

Samba service

We can check that Samba is currently running and ready to serve connections.

sudo service smbd status | egrep 'Active|Status'
Active: active (running) since Fri 2025-05-01 21:09:51 UTC; 5min ago
Status: "smbd: ready to serve connections..."

As you can see, Samba is up and running.

Samba connections

This command will only show us Samba connections that are currently being accessed.

sudo smbstatus -S
Service      pid     Machine       Connected at                     Encryption   Signing
---------------------------------------------------------------------------------------------
DUMPSTER     8720    192.168.1.234 Thu Apr 30 10:23:10 AM 2025 UTC  -            -

This tells me that DUMPSTER is currently being accessed.