Samba (Open Source Implementation of the Microsoft's SMB Networking Protocol)

A Samba file server enables file sharing across different operating systems over a local area network. It lets you access your desktop files from a laptop and share files with Windows and macOS users.

Installing Samba (on Ubuntu)

To install Samba, we run:

sudo apt update
sudo apt install samba

(In some scenarios you may also want to install samba-testsuite.)

Configuring Samba

Once Samba has been installed, we need to create a directory for it to share:

mkdir /home/username/sambashare/

The command above creates a new folder sambashare in our home directory which we will share later, but you could share some other forlder.

The configuration file for Samba is located at /etc/samba/smb.conf. To add the new directory as a share, we edit the file by running:

sudo vi /etc/samba/smb.conf

(You may use other editors such as nano or emacs)

At the bottom of the file, add the following lines:

[sambashare]
    comment = Samba on Ubuntu
    path = /home/username/sambashare
    read only = no
    browsable = yes

To allow clients (specifically Windows 10 ones) to write to the share you should add:

create mask = 0775
directory mask = 0775

Then save and exit from your chosen text editor.


This is what we've just added


Now that we have our new share configured, save it and restart Samba for it to take effect:

sudo service smbd restart

Also, remember to update the firewall rules to allow Samba traffic:

sudo ufw allow samba

An Updated Configuration

The provided Samba configuration is outdated and incorrect. Many new changes have been made which makes those setting invalid. Here are the correct settings (works with Windows):

[ Movies]
comment = Movies on Red Tail
path = /mnt/share/movies
read only = no
browsable = yes
public = yes
force user = root
write list = root
create mask = 0775
directory mask = 0775
acl allow execute always = True

...

Adding wsdd to Make Shares Visible to Windows

I'd like to suggest telling people they will need wsdd if they want their Linux Samba shares to be visible on Windows. I know wsdd is not part of the Samba project but it (or an equivalent) is essential for most users and not telling them up-front to install it just leads to frustration and unnecessary help requests about Samba doesn't work with Windows clients etc.

sudo apt install wsdd is sufficient for most users on a local network (by default wsdd listens on all interfaces, but can be configured via /etc/default/wsdd).

Setting up User Accounts

Since Samba doesn't use the system account password, we need to set up a Samba password for our user account:

sudo smbpasswd -a username

and follow up with

sudo smbpasswd -e username

Note: The -e switch enables the user.

Note. The username used must belong to a system account, else it won't save.

Connecting to a Share

On Ubuntu

Open up the default file manager and click Connect to Server then enter:

smb://ip-address/sambashare
On macOS

In the Finder menu, click Go > Connect to Server then enter

smb://ip-address/sambashare
On Windows

open up File Manager and edit the file path to:

\\ip-address\sambashare

Note: ip-address is the Samba server IP address and sambashare is the name of the share.

You'll be prompted for your credentials. Enter them there your are!