Create a Samba network share

Create a Samba network share

Create a network share using Samba on Ubuntu

Last updated:

linux nas ubuntu


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
Samba version 4.7.6-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 main settings for Samba are contained within /etc/samba/smb.conf. However, shares can be added by creating a config file for the share in /var/lib/samba/usershares.

User share

A user share is where a specific user or group will have access. Lets create a new file to contain our share settings.

sudo nano /var/lib/samba/usershares/dumpster_myshare

Then add the following items to the file.

comment=Comment: /DUMPSTER/myshare

Make sure you restart Samaba after making these changes.

sudo smbd reload

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

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 /var/lib/samba/usershares/dumpster_myshare

Then change guest_ok to y.


Then restart Samaba.

sudo smbd reload

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 2020-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 Thu Apr 30 10:23:10 AM 2020 UTC  -            -

This tells me that DUMPSTER is currently being accessed.