How to Install and Configure Samba Server on Ubuntu 16.04 for File Sharing

In this tutorial, we’re going to learn how to install and configure a samba server on Ubuntu 16.04. Samba is a free and open-source SMB/CIFS protocol implementation for Unix and Linux that allows for file and print sharing between Unix/Linux and Windows machines in a local area network.

Samba is a suite of programs, the most important two of which are:

  • smbd: which provides SMB/CIFS service (file sharing and printing), can also act as a Windows domain controller.
  • nmbd: which provides NetBIOS name service

How to Install Samba Server on Ubuntu 16.04

Samba is included in most Linux distributions. To install Samba on Ubuntu, simply run:

sudo apt install samba

The latest stable version available is 4.5.3, released on December 19, 2016. To check your Samba version, run

sudo smbstatus


sudo smbd --version

Sample output:

Samba version 4.3.11-Ubuntu

To check if Samba service is running, issue the following commands.

systemctl status smbd

systemctl status nmbd

To start these two services, issue the following commands:

sudo systemctl start smbd

sudo systemctl start nmbd

Once started, smbd will be listening on port 139 and 445.

Editing the Configuration File

There’s only one configuration file that needs to be taken care of: /etc/samba/smb.conf.

sudo nano /etc/samba/smb.conf

In the [global] section, make sure the value of workgroup is the same with the workgroup settings of Windows computers.

workgroup = WORKGROUP

The scroll down to the bottom of the file. (In nano text editor, press CTRL+W then CTRL+V. ) Add a new section like below. Replace username with your desired username.

[Home Share]

comment = Home Public Folder
path = /home/username/
writable = yes
valid users = username

Home Share is the folder name that will be displayed on the Windows network. The comment is a description for the shared folder. The next 3 lines indicate that only the user specified by valid users has access right to the /home/username/ directory, which is also writable. The above configurations will disable anonymous access.

Save and close the file, then run the following command to check if there’s syntactic errors.


Creating an User Account

Samba by default sets user as the security mode which means clients must enter a username and password for a shared folder. To add a user on Ubuntu, run the following command. Replace username with your desired username.

sudo adduser username

You will be prompted to set an Unix password. You also need to set a separate Samba password for the new user with the following command:

sudo smbpasswd -a username

Now all left to do is to restart smbd daemon.

sudo systemctl restart smbd

Accessing Samba Shared Folder From Windows

On a Windows computer that is in the same network, open file explorer and click Network on the left pane. You will see the samba server. Double click the shared folder and enter the username and password.

Accessing Samba Share Folder From a Ubuntu Computer

In your file manager, click the Network tab on the left pane and click Windows Network.

samba server ubuntu 16.04

Select the workgroup, your Samba server and the shared folder, then enter the Samba username and password.

samba ubuntu

Adding Multiple Users or Groups

If multiple accounts are more suitable for accessing the shared folder , then change valid users like below in /etc/samba/smb.conf file.

valid users = user1, user2, user3

Also use smbpasswd to set a Samba password for each of these users.

sudo smbpasswd -a user1

sudo smbpasswd -a user2

sudo smbpasswd -a user3

To allow a group of users to access the shared folder, use the following config in /etc/samba/smb.conf.

valid users = @sambashare

Create the group.

sudo groupadd sambashare

Then add users to this group

sudo gpasswd -a user1  sambashare

sudo gpasswd -a user2 sambashare

sudo gpasswd -a user3 sambashare

The group needs to have write permission to the shared folder which can be achieved with the following two commands.

Set sambashare as the group owner of the shared folder:

sudo chgrp sambashare /path/to/shared/folder -R

Grant write permission to the group.

sudo chmod g+w /path/to/shared/folder/ -R

That’s it!

I hope this tutorial helped you set up Samba server on Ubuntu 16.04. As always, if you found this post useful, then subscribe to our free newsletter. You can also follow us on Google+ Twitter or like our Facebook page.

Rate this tutorial
[Total: 47 Average: 3.6]