How to set up a Samba file server to use with Windows clients

According to the Samba project web site, Samba is an open source/free software suite that provides seamless file and print services to SMB/CIFS clients. Unlike other implementations of the SMB/CIFS networking protocol (such as LM Server for HP-UX, LAN Server for OS/2, or VisionFS), Samba (along with its source code) is freely available (at no cost to the end user), and allows for interoperability between Linux/Unix servers and Windows/Unix/Linux clients.

For these reasons, Samba is the preferred solution for a file server in networks where different operating systems (other than Linux) coexist - the most common setup being the case of multiple Microsoft Windows clients accessing a Linux server where Samba is installed, which is the situation we are going to deal with in this article.

Please note that on the other hand, if our network consists of only Unix-based clients (such as Linux, AIX, or Solaris, to name a few examples), we can consider using NFS (although Samba is still an option in this case), which has greater reported speeds.

Installing Samba in Debian and CentOS

Before we proceed with the installation, we can use our operating system's package management system to look for information about Samba:

On Debian:

# aptitude show samba

On CentOS:

# yum info samba

In the following screenshot we can see the output of 'aptitude show samba' ('yum info samba' yields similar results):

Now let's install Samba (the screenshot below corresponds to the installation on a Debian 7 [Wheezy] server):

On Debian:

# aptitude install samba

On CentOS:

# yum install samba

Adding Users to Samba

For versions earlier than 4.x, a local Unix account is required for adding users to Samba:

# adduser -s /dev/null -m -d /home/<username> <username>

Next, we need to add the user to Samba using the smbpasswd command with the '-a' option, which specifies that the username following should be added to the local smbpasswd file. We will be prompted to enter a password (which does not necessarily have to be the same as the password of the local Unix account):

# smbpassword -a <username>

Finally, we will give access to user xmodulo to a directory within our system that will be used as a Samba share for him (and other users as well, if needed). This is done by opening the /etc/samba/smb.conf file with a text editor (such as Vim), navigating to the end of the file, and creating a section (enclose name between square brackets) with a descriptive name, such as [xmodulo]:

path = /home/xmodulo
available = yes
valid users = xmodulo
read only = no
browseable = yes
public = yes
writeable = yes

We must now restart Samba and -just in case- check the smb.conf file for syntax errors with the testparm command:

# service samba restart
# testparm

If there are any errors, they will be reported when testparm ends.

Mapping the Samba Share as a Network Drive on a Windows 7 PC

Right click on Computer, and select "Map network drive":

Type the IP address of the machine where Samba is installed, followed by the name of the share (this is the name that is enclosed between single brackets in the smb.conf file), and make sure that the "Connect using different credentials" checkbox is checked:

Enter the username and password that were set with 'smbpasswd -a' earlier:

Go to Computer and check if the network drive has been added correctly:

As a test, let's create a pdf file from the man page of Samba, and save it in the /home/xmodulo directory:

Next, we can verify that the file is accessible from Windows:

And we can open it using our default pdf reader:

Finally, let's see if we can save a file from Windows in our newly mapped network drive. We will open the change.log file that lists the features of Notepad++:

and try to save it in Z:\ as a plain text file (.txt extension); then let's see if the file is visible in Linux:

Enabling quotas

As a first step, we need to verify whether the current kernel has been compiled with quota support:

# cat /boot/config-$(uname -r) | grep -i config_quota

Each file system has up to five types of quota limits that can be enforced on it: user soft limit, user hard limit, group soft limit, group hard limit, and grace time.

We will now enable quotas for the /home file system by adding the usrquota and grpquota mount options to the existing defaults option in the line that corresponds to the /home filesystem in the /etc/fstab file, and we will remount the file system in order to apply the changes:

Next, we need to create two files that will serve as the databases for user and group quotas: aquota.user and, respectively, in /home. Then, we will generate the table of current disk usage per file system with quotas enabled:

# quotacheck -cug /home
# quotacheck -avugm

Even though we have enabled quotas for the /home file system, we have not yet set any limits for any user or group. Check for quota information for existing user/group:

# quota -u <username>
# quota -g <groupname>

Finally, the last couple of steps consist of assigning the quotas per user and / or group with the quotatool command (note that this task can also be performed by using edquota, but quotatool is more straightforward and less error-prone).

To set the soft limits to 4 MB and the hard limit to 5 MB for the user called xmodulo, and 10 MB / 15 MB for the xmodulo group:

# quotatool -u xmodulo -bq 4M -l '5 Mb' /home
# quotatool -g xmodulo -bq 10M -l '15 Mb' /home

And we can see the results in Windows 7 (3.98 MB free of 4.00 MB):

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work. When he's not typing commands or writing code or articles, he enjoys telling bedtime stories with his wife to his two little daughters and playing with them, the great pleasure of his life.

7 thoughts on “How to set up a Samba file server to use with Windows clients

  1. I am unable to connect to my Samba server with Windows 8.1 clients. No problems with my Windows 7 clients. Is there something different that needs to be done on my Win8.1 clients?

    • Hello, I found out on my first Zentyal deployment with Windows 8.1 clients that I had to disable SMB 2.0 and 3.0 on the 8.1 machines so they could stay connected to the Samba shares.

    • Hi Sam,
      This is Gabriel Cánepa, the author of this article.
      I just installed Windows 8.1 Pro and was able to use the same Samba installation to access the share I created for this tutorial without any issues.
      Feel free to upload your smb.conf file to a file hosting provider and send me the link. I'll be more than glad to take a look to see if I can help you solve your issue.
      Best regards.

  2. Hello Mr. Gabriel Cánepa / Va salut Domnule Canepa

    One small observation:

    It is not wise to create system users for samba, like you mention. It is more safe to use something like this:

    adduser -s /dev/null -m -d /home/xmodulo xmodulo

    I think you want that samba users to make logins ONLY in samba and not to use anothers services who are on the same server .... ;)

  3. @Iulian Murgulet,
    Thank you for your comment. I understand your point of view, but I believe it would be more applicable to the case when Samba acts as a DC instead of a simple file server, as it is the case in this post. There is another article about that topic in this same website (
    Other than that, I think it's a matter of personal preference. However, feel free to state your reasons why you think it is unsafe.
    That being said, thanks a lot for bringing this to my attention and for contributing to this article!

    • Usually, nobody installs on a server only samba. So it is unsafe if a samba user will also have an ssh access. Anybody will have ssh server installed .... as you already know. So the samba user will have the possibility to use ssh. And if this users are also windows users, and their windows PCs are hacked, then the hackers will have a good chance to make an ssh connection on the samba server (because in most cases, user/password on samba are very simple).

      For this reason and others, on any samba server (Primary/Backup Domain Controller, File Server,etc) I make samba user without a shell access (/dev/null), and use fail2ban.

Leave a comment

Your email address will not be published. Required fields are marked *