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 contains several programs that serve different but related purposes, the most important two of which are:

  • smbd: provides SMB/CIFS service (file sharing and printing), can also act as a Windows domain controller.
  • nmbd: This daemon provides NetBIOS name service, listens for name-server requests. It also allows the Samba server to be seen by other computers on the network.

How to Install Samba Server on Ubuntu 16.04

Samba is included in most Linux distributions. To install Samba on Ubuntu, simply run the following command in terminal.

sudo apt install samba samba-common-bin

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

sudo smbstatus


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 TCP port 139 and 445. nmbd will be listening on UDP port 137 and 138.

  • TCP 139: used for file and printer sharing and other operations.
  • TCP 445: the NetBIOS-less CIFS port.
  • UDP 137: used for NetBIOS network browsing.
  • UDP 138: used for NetBIOS name service.

Create a Private Samba Share

In this section, we will see how to create a private Samba share that requires the client to enter username and password in order to gain access. The main Samba configuration file is located at: /etc/samba/smb.conf. You can edit it in terminal with a command line text editor like nano.

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

samba share ubuntu

You can find the setting on your Windows computer by going to Control Panel > System and Security > System.

samba ubuntu server

The scroll down to the bottom of the file. (In nano text editor, you can achieve that by pressing CTRL+W then CTRL+V. ) Add a new section like below.


comment = needs username and password to access
path = /srv/private/
browseable = yes
guest ok = no
writable = yes
valid users = @samba


  • Private is the folder name that will be displayed on the Windows network.
  • The comment is a description for the shared folder.
  • The path parameter specifies the path to the shared folder. I use /srv/private/ as an example. You can also use a folder in your home directory.
  • browseable = yes: Allow other computers in the network to see the Samba server and Samba share. If set to no, users have to know the name of the Samba server and then manually enter a path in the file manager to access the shared folder.
  • guest ok = no: Disable guest access. In other words, you need to enter username and password on the client computer to access the shared folder.
  • writable = yes: Grants both read and write permission to clients.
  • valid users = @samba: Only users in the samba group are allowed to access this Samba share.

Save and close the file. (To save the file in nano text editor, press Ctrl+O, then press Enter to confirm the file name to write. To close the file, press Ctrl+X.) Now we need to create a Samba user. First, we need to create a standard Linux user account with the following command. Replace username with your desired username.

sudo adduser username

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

sudo smbpasswd -a username

Create the samba group.

sudo groupadd samba

And add this user to the samba group.

sudo gpasswd -a username samba

Create the private share folder.

sudo mkdir /srv/private/

The samba group needs to have read, write and execute permission on the shared folder. You can grant these permissions by executing the following command.

sudo setfacl -R -m "g:samba:rwx" /srv/private/

Next run the following command to check if there’s syntactic errors.


Now all left to do is to restart smbd and nmbd daemon.

sudo systemctl restart smbd nmbd

How to Create a Samba Public Share Without Authentication

To create a public share without requiring username and password, the following conditions must be met.

  • Set security = user  in the global section of Samba configuration file. Although you can create a public share with the security = share mode, but this security mode is deprecated. It is strongly suggested that you avoid share mode.
  • Set map to guest = bad user in the global section of Samba configuration file. This will cause smbd to use a guest account to authenticate clients who don’t have registered account on the Samba server. Since it’s a guest account, Samba clients don’t need to enter password.
  • Set guest ok = yes in the share definition to allow guest access.
  • Grant read, write and execute permission of the public folder to the nobody account, which is the default guest account.

As a matter of fact, the first two conditions are already met as Samba by default uses these two settings.

Here’s a step-by-step guide to create a public share. First, open and edit the Samba configuration file.

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

samba share ubuntu

You can find the setting on your Windows computer by going to Control Panel > System and Security > System.

samba ubuntu server

Then scroll down to the bottom of the file and paste the following lines.


comment = public share, no need to enter username and password
path = /srv/public/
browseable = yes
writable = yes
guest ok = yes

Save and close the file. Next, create the /srv/public/ folder.

sudo mkdir /srv/public

Then make sure the nobody account has read, write and execute permission on the public folder by executing the following command.

sudo setfacl -R -m "u:nobody:rwx" /srv/public/

Restart smbd and nmbd.

sudo systemctl restart smbd nmbd

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. Then double-click the hostname of your Ubuntu computer. For example, the hostname of my Ubuntu 16.04 computer is xenial.

samba ubuntu setup

Then double-click the shared folder. To access private share, you need to enter the samba username and password. You don’t need to do so to access public share.

samba public share

Once connected, you can read, write and delete files in the Samba shared folder. Note that if you access the private share and public share at the same time, you may not be able to create files or folders in the public share.

Connecting Error

If you get the following error:

You do not have permission to access \\hostname\share-name. Contact your network administrator to request access.

You can try connecting to the Samba share from the command prompt. Open up a command prompt, then run the following command to close current Samba session.

net use \\hostname\share-name /delete

Next, connect to the Samaba share with the following command:

net use \\hostname\share-name /user:samba-username password

Once the above command completed successfully, go to the Network tab in File Explorer and now you should be able to access the Samba share.

Drive Mapping

One feature of the Windows operating system is the capability to map a drive letter (such as S:) to a remote directory. To map the drive letter S: to the Samba share, open up command prompt and run the following command.

net use s: \\hostname\share-name

For example, my hostname is xenial and the name of my Samba shared folder is home, so I run

net use s: \\xenial\home

Once the drive mapping is established, applications can access the files in the Samba share through the drive letter S:.

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

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: 82 Average: 4.1]

15 Responses to “Install and Configure Samba Server on Ubuntu 16.04 for File Sharing

  • Larry Viesse
    2 years ago

    Thanks, nice work, as simple as it gets!

    Just one issue, [Home Share ] should be [Home Share], note the trailing space in the former.

  • Jenrry Dextre
    2 years ago

    hola amigo yo le hice un pequeño cambio por que no me permitia escribir, ni eliminar, yo hice lo siguiente:

    [email protected]:/srv# chown -R cliente1:samba privado cliente1=username, samba=is the group, privado=name of the file.
    [email protected]:/srv# systemctl restart smbd nmbd
    [email protected]:/srv# chmod -R 777 privado
    [email protected]:/srv# ls -l
    total 4
    drwxrwxrwx+ 3 cliente1 samba 4096 mar 10 02:16 privado

    ahora ya tengo acceso total a la carpte privado y desde mis lado (gnu/linux)

  • Kid.Drunkadelic
    2 years ago

    follow this to a T, windows does not allow me to do anything with this

  • tb thomas
    2 years ago

    The tutorial says the latest samba version is 4.5.3. I’ve got 4.3.11. How do I install the latest version?
    (Thanks in advance.)

    • Xiao Guo-An (Admin)
      2 years ago

      4.3.11 is fine. If you don’t have a strong reason to use 4.5.3, stick with your current version.

  • hvala

  • Jennifer
    1 year ago

    So, this messed up my computer. I am not sure what I did. I was just trying to set up my wireless printer. I can send you the log if you want.

  • Gineer Catalyst
    1 year ago

    Is your instruction correct “sudo adduser username” should it be
    sudo useradd username?

     sudo adduser SmbGuy
    adduser: Please enter a username matching the regular expression configured
    via the NAME_REGEX[_SYSTEM] configuration variable.  Use the `--force-badname'
    option to relax this check or reconfigure NAME_REGEX.

    Your instruction is correct “

  • nolwenn
    1 year ago


    I want private folder but when i click, ,it don’t ask my password . Why ? I read your tuto.
    Can you help me ?

    Thanks you

  • Steve R.
    10 months ago

    I have Ubuntu 16.04. I just installed Samba Version 4.7.12. When I click on the “share” button and then “create share” for my public share share folder, I receive the following error message:

    'net usershare' returned error 255: net usershare add: cannot convert name "Everyone" to a SID. The transport-connection attempt was refused by the remote system.. Maybe smbd is not running.

    When I issue:

    sudo systemctl start smbd

    , I get the error message:

    Failed to start smbd.service: Unit smbd.service not found.

    . Is there a fix?

  • Steve R.
    10 months ago

    Please delete my prior post and this post. I went back to Samba Version 4.3.11-Ubuntu. I believe the newer version of Samba (Version 4.7.12) may be incompatible with Ubuntu 16.04. Thank-you.

  • Ans Helm
    3 months ago

    Thnks a lot. Very useful tutorial

  • Nigel Wood
    3 months ago

    Firstly, I have zero expertise in ubuntu, but over the last year I have tried to convert an old laptop to 18.04 and have attempted to follow the tutorial on installing a Samba server for file sharing but have always failed to be 100% satisfactory. The need for Samba is I would like to print to the printer on my Windows 10 machine. I must be nearly OK as the win10 machine sees the ubuntu and I can paste from it. Also, I can identify the printer on the win 10 machine when adding a printer on the ubuntu laptop but when attempting to print it sticks on a request for authentication, as none I my username or passwords that I have set trigger this authentication. Although they have worked in SMB to identify the printer. I guess I must be doing something wrong in terminal any suggestions?

  • Massimiliano
    2 months ago

    Perfect guide Thank you

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community ( for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.