Samba Server installation on Ubuntu 16.04

This guide explains the installation and configuration of a Samba server on Ubuntu 16.04 (Xenial Xerus) with anonymous and secured Samba shares. Samba is an Open Source/Free Software suite that provides seamless file and print services to SMB/CIFS clients. Samba is freely available, unlike other SMB/CIFS implementations, and allows for interoperability between Linux/Unix servers and Windows-based clients.

1 Preliminary Note

I have fresh installed Ubuntu 16.04 server, on which I am going to install the samba server. As Samba client system, I will use a Windows Desktop to connect to the samba server and check the setup. The Windows Desktop should be in the same network so that it is able to reach the Ubuntu server. The hostname of my Ubuntu server is and the IP is

If you don't have a Ubuntu server already, follow this tutorial to get a minimal server setup as the basis for this tutorial.

Note: The Windows machine must be in the same workgroup. To check the value in the Windows machine run the following command at cmd prompt:

net config workstation

The output will be like this:

Get the Windows Workgroup name.

Your Windows machine must be in the same Workstation domain as the Ubuntu server, i.e. WORKGROUP in my case.

To make the windows machine reachable in Windows by its hostname, proceed like this. Open a Windows terminal in administrator mode (you can reach the administrator mode by doing a right-click on the Terminal icon in the program menu) and run the following command to open the Windows hosts file:

notepad C:\\Windows\System32\drivers\etc\hosts

There you add the following red line and save the file:

[...] server1

The following steps have to be run as root user. Run:

sudo -s

on the shell of your Linux server to become the root user.

2 Anonymous Samba sharing

Samba is available in the Ubuntu repositories. The first step is to install the Samba Server and its dependencies with apt.

apt-get install -y samba samba-common python-glade2 system-config-samba

It will install the Samba version 4.3.9-Ubuntu.

To configure samba, edit the file /etc/samba/smb.conf. I will use nano as editor and make a backup of the original file before I start to change it. The backup file is named /etc/samba/smb.conf.bak

cp -pf /etc/samba/smb.conf /etc/samba/smb.conf.bak
cat /dev/null  > /etc/samba/smb.conf

Open the Samba configuration file with nano:

nano /etc/samba/smb.conf

And add the following lines.

workgroup = WORKGROUP
server string = Samba Server %v
netbios name = ubuntu
security = user
map to guest = bad user
dns proxy = no

#============================ Share Definitions ==============================
[Anonymous] path = /samba/anonymous browsable =yes writable = yes guest ok = yes read only = no
force user = nobody

Then I'll create a directory for the anonymous share.

mkdir -p /samba/anonymous

Set the correct permissions.

chmod -R 0775 /samba/anonymous
chown -R nobody:nogroup /samba/anonymous

And restart Samba to apply the new configuration.

service smbd restart

Now you can access the Ubuntu sharing in Windows by entering "\\server1" in the windows search field of the menu or use the network browser of the Windows file explorer to connect to the share.

The Samba anonymous share shows up in Windows.

Try to upload a file by Drag&Drop to the share to see if it is working correctly.

The Upload to the anonymous Samba share was successful.

You can cross check the content at server also.

ls -la /samba/anonymous/

[email protected]:/samba/anonymous# ls -la /samba/anonymous/
total 16
drwxrwxr-x 2 nobody nogroup 4096 Jun 1 18:46 .
drwxr-xr-x 3 root root 4096 Jun 1 18:39 ..
-rwxr--r-- 1 nobody nogroup 7405 Jun 1 18:42 test.odt
[email protected]:/samba/anonymous#

3 Secured Samba server

For the password-protected share, I will create a group smbgrp and user till to access the Samba server. I'll use "howtoforge" as password in this example, please choose a custom and secure password on your server.

addgroup smbgrp

useradd till -G smbgrp

smbpasswd -a till

[email protected]:~# smbpasswd -a till
New SMB password:<--howtoforge
Retype new SMB password:<--howtoforge
Added user till.
[email protected]:~#

Now create the folder with the name "secured" in the /samba folder and give permissions like this

mkdir -p /samba/secured
cd /samba
chmod -R 0770 secured
chown root:smbgrp secured

Edit the Samba configuration file and add the following (red) lines at the end of the file:

nano /etc/samba/smb.conf

[secured] path = /samba/secured valid users = @smbgrp guest ok = no writable = yes browsable = yes

service smbd restart 

To cross-check the settings, run this command:


[email protected]:/samba# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[Anonymous]"
Processing section "[secured]"
Loaded services file OK.

Press enter to see a dump of your service definitions <-- Press Enter

# Global parameters
netbios name = UBUNTU
server string = Samba Server %v
security = USER
map to guest = Bad User
dns proxy = No
idmap config * : backend = tdb

path = /samba/anonymous
force user = nobody
read only = No
guest ok = Yes

path = /samba/secured
valid users = @smbgrp
read only = No

At the Windows machine, open the "\\server1" network device again, it will request a username and password now. Enter the user details that you created above. In my case, the values were user=till and password=howtoforge.

Login to the Samba share.

Both Samba shares show in Windows Explorer.

The test-upload worked.

We can check the file at the Ubuntu server like this:

ls -la /samba/secured/

[email protected]:/samba# ls -la /samba/secured/
total 16
drwxrwx--- 2 root smbgrp 4096 Jun 1 19:25 .
drwxr-xr-x 4 root root 4096 Jun 1 18:49 ..
-rwxr--r-- 1 till till 7405 Jun 1 18:42 test.odt
[email protected]:/samba#

Now we have a successfully configured Samba server with an anonymous and a secured share on Ubuntu 16.04 :)

4 Virtual machine image download of this tutorial

This tutorial is available as ready to use virtual machine image in ovf/ova format that is compatible with VMWare and Virtualbox. The virtual machine image uses the following login details:

SSH / Shell Login

Username: administrator
Password: howtoforge

This user has sudo rights.

The IP of the VM is, it can be changed in the file /etc/network/interfaces. Please change all the above passwords to secure the virtual machine.

Share this page:

19 Comment(s)

Add comment


From: Marcelo at: 2016-06-01 19:11:52

How I upgrade Samba after Instalation?

From: till at: 2016-06-02 07:04:42

Just update your system regularly with:


apt-get update

apt-get upgrade


this will install Samba updates as well as all other system updates.

From: Zoltan at: 2016-06-03 09:28:31

How to create a common share?

From: John at: 2016-06-05 10:42:32

i noticed you installed the system-config-samba which i believe it is the gui utility for samba. i did the same but gui keep crashng. any idea?

From: kashminder at: 2016-06-08 05:03:02

after deploying the setup i can share the directory but the folder is not accessible in windows(shows folder). It says "you might not have permissions to use this network"

From: rumples at: 2016-06-14 19:00:52

 Awesome writeup, pitty you are a rare bread amongst linux users, meaning this is the best guide to SAMBA by a long way!!!

From: Darryl at: 2016-06-26 12:44:05

What is the purpose of creating "smbgrp" if the samba installation already creates the group "sambashare"?  Why not just use that existing group? 

From: easyrider6721 at: 2016-07-14 06:27:59

This command did not work at all,  (notepad C:\\Windows\System32\drivers\etc\hosts)

These commands did nothing .... (cp -pf /etc/samba/smb.conf /etc/samba/smb.conf.bakcat /dev/null  > /etc/samba/smb.conf)

I copied and pasted this in the window......

[global] workgroup = WORKGROUP server string = Samba Server %v netbios name = ubuntu security = user map to guest = bad user dns proxy = no #============================ Share Definitions ============================== [Anonymous] path = /samba/anonymous browsable =yes writable = yes guest ok = yes read only = noforce user = nobodyafter Opening the Samba configuration file with nano had no instructions what to do after that. couldnt save it couldnt add it to file.....I am no closer to having my server set up than i was before i read all this.... obviously i am a newbee and i am frustrated with all the how to stuff on the web with missing steps......


From: till at: 2016-07-14 06:43:22

Thanky ou for your report. I just installed the tutorial again to verify it and there are no issues in the tutorial, all commands are working and it results in a fully working samba server. If a command does not return anything on Linux then it means that it worked, if it would not have worked then you would have gotten an error message, so the commands you posted are working file and they did exactly what they should (make a copy of the configuration file and create a new empty file.

From: Jorge Vilela at: 2016-07-15 16:24:03

First, thank you for the guide. It is very usefull.

But I have a problem, I created the secure samba server. But in windows when I try to use it, windows gives me an error.

"Multiple connections to a server or shared resource by the same user, using more than one user name are not allowed. Disconnect all previous connections to the server or shared resource and try again."

How can I solve this?

Thank you.

From: Aure at: 2016-08-02 16:54:23

Hola a [email protected]!!!

Yo tenía Ubuntu 14.04 como servidor y a él se conectan equipos linux con Samba, desde que actualicé a 16.04 estuve viernes 29 Jul, sábado 30 Jul y Lunes 01 Ago. No sé qué fue lo que quedó mal con la configuración porque ya no pude más acceder a las carpetas y ni a las impresoras de Linux desde Windows. Intenté un montón de configuraciones de versiones anteriores de Ubuntu y ninguna me funcionó.

Hasta que encontré este lugar y quedó de nuevo trabajando, cambiando la instrucción (de acuerdo al ejemplo, solo cambiando la ruta de mis carpetas):

chown -R nobody:nogroup /samba/anonymous por chown -R serverlinux:nogroup /MiRed/MisCarpetas

ya que al principio probé con nobody, podía accesar a carpetas y archivos pero no grabar.

Solo me queda reconfigurar las impresoras que aún lo tengo pendiente, por ahora la impresora la tengo instalada en modo compartida en un equipo con Windows, a ver si pueden escribir un pequeño manual para saber cómo configurarlas. Además, la manera de restringir a usuarios a ciertas carpetas es la parte que también explican aqui pero que aun no lo he probado.

Quiero comentar también que en Linux soy novato y esta explicación fue muy entendible a comparación de otros que encontré ne la web.

Muchas gracias.



From: Aure at: 2016-08-03 17:24:13

Hola a [email protected]!!

Por alguna razón de un día para otro, me volvió a dar problemas de conexión. Lo que haré ahora es hacer una instalación limpia de Ubuntu 16.04 y a ver si con eso se resuelve, porque lo que hice fue hacer actualización desde versión 14.04 a ésta nueva versión.

Ya les estaré contando, saludos.

From: Aure at: 2016-08-04 00:41:05

El problema que encontré es que se desconecta del wifi sin razón alguna y no la configuración de Samba, al parecer es del mismo administrador del wifi de Ubuntu.

Buscando en internet, encontré que no nada más a mí me está pasando la desconexión y dieron una solución temporal que funciona y es la siguiente:

sudo service network-manager restart (fuente:

De ser posible, hacerlo varias veces hasta que se vuelva a reconectar. A mí, del todo no me conviene ya que tengo un sistema en red y a mis compañeros que se conectan a ella, a cada rato los "bota" del sistema.

Espero y se resuelva pronto esto por parte del equipo de Ubuntu o de plano instalar una versión anterior.



From: Martin 0105 at: 2016-08-05 07:22:18

after installing samba in anonymous configuration one major difficulty occured: I was able to create a subfolder from my Windows 10 desktop, but the subfolder does not have write permission and I cannot change the permission in Windows 10. Of course I can change the permissions on the server, but that is not really a good workaraound. What did I d wrong?

From: Martin 0105 at: 2016-08-10 17:16:19

What I did wrong was to install Windows 10 ...

As Admin on Windows 10, I was finally able to change permissions on the Anonymous folder and all subfolders. So it works fine.

From: obaino at: 2016-08-21 21:14:09

excuse but I cannot find the link to download the vm image of this tutorial

From: till at: 2016-08-22 07:55:32

Upper right corner, below the big red download icon.

From: Dirk at: 2016-10-03 18:36:08

After trying the two gui's for configuring samba several times I waited to find time to try the manually config. With your tutorial it was that easy - why didn't I try earlier ;) Thanks!

From: ben1828 at: 2016-10-22 00:00:04

Thank you - a great help :)