How to share directories between Linux and Windows

botond published 2018. 11. 20., K - 14: 28 time

The 1. page content


It is important to share back and forth between computers on a network, including both Linux and Windows computers. Between Linux systems About NFS-based File Sharing I have already made another description, but in order to make Linux shares that are accessible from Windows, or to access Windows shares from Linux, we now need to use other tools.

In this tutorial, we will walk you through this topic step by step, which we can follow with concrete, working examples.

The examples cover the following situations:

  • Access a Debianon shared directory on Windows 7 systems.
  • Access a shared directory on Windows 7 on Debian systems.
  • Manage shares between Debian 8 and / or 9 operating systems

I use Debian 8, Debian 9, and Windows 7 on my home computers, so I can use these to show the Samba sharing settings in action.

Installing and configuring the package on Debian

Before getting started, it is always a good idea to upgrade your repository and packages (as root) to the usual apt-get commands:

apt-get update
apt-get upgrade

This way, we can be sure that we can work with the latest software in our distribution.

Next, install the packages needed to run Samba shares:

Samba server

The packages you install below are responsible for running "outbound" shares to be created on Debian (or any Debian-based distribution):

apt-get -y install libcups2 samba samba-common cups

Of these, the libcups2 and the cups they are responsible for network printing if we want to share printers as well.

Samba client

These are needed to handle "outside" shares on Debian:

apt-get -y install samba-client cifs-utils

Here is the samba-client (or smbclient) is clear, a cifs-utils and ensures the compatibility of file systems shared between different platforms (Linux, Windows, OS X, etc.).


After installing the packages, you will need to create your own Samba configuration file, which will be customized for your machine or network.

First, make a backup of the factory Samba configuration file to keep in case you need to (while still remaining root):

mv /etc/samba/smb.conf /etc/samba/smb.conf.bak

Then create your own (eg with nano editor):

nano /etc/samba/smb.conf

And let's include the following:

    workgroup = WORKGROUP
    server string = Samba Server %v
    netbios name = SZAMITOGEP-NEVE
    map to guest = bad user
    security = user
    encrypt passwords = yes
    dns proxy = no

This is the general default for the Samba server, where line items have the following meaning:

  • workgroup: This is the workgroup of our network. Ideally, all computers are set to the same, for example, on a home network. By default, this is "WORKGROUP" in Windows. So if we didn't set it up on the other machines, that's fine.
  • server string: Detailed description of the machine. Eg from Windows a Displays in the Network Neighborhood panel for details.
  • netbios name: The network name of the computer. Enter the exact computer name that you gave to the machine during installation. (THE hostname can also be issued by command)
  • map to guest: Guest access control. If you do not plan guest access to shares, remove this line or set it to "Never" (this is the default)
  • security: This controls whether authentication is done on a per-user basis ("user" setting) or with passwords ("share") assigned separately to shares.
  • encrypt passwords: Whether to encrypt passwords when sending over the network
  • dns proxy: If you are using a DNS Proxy server, you need to enable it here. Otherwise, leave it like that.

Of course, there are many other settings for the Samba server, but that is enough for it to work.

Save the file, then restart the Samba daemon a systemctl via:

systemctl restart smbd.service

So we've prepared our Linux system for bidirectional sharing. All we have to do is create our first share.

Create a Samba share on Debian

Let's create a directory somewhere we want to share.

For the sake of testing, I created a "Share" directory on my laptop under my user (with my own user) and contained two test files:

Samba Sharing Debianon - Test Directory Structure

This is what I'm going to introduce to sharing now, of course, you can experiment with any library.

Re-open the previously edited Samba configuration file as root:

nano /etc/samba/smb.conf

And add the following section after the basic settings above:

    path = /home/botond/Megosztás
    create mask = 0644
    directory mask = 0755
    read only = no
    browsable = yes
    writable = yes
    valid users = botond
    map archive = no

Here the line items mean:

  • [Share]: This will be the name of our share. I just entered the same name as my library to share, but anything else can be entered. This will appear on the network as you browse.
  • path: Access the directory you want to share.
  • create mask: Authorization mask for files created in the shared directory. This option will create 0644 privileges to create newly created files from the remote machine.
  • directory mask: Same with remotely created subdirectories.
  • read only: Read-only sharing
  • browsable: Is it possible to browse, search in the shared library, or to access files / subdirectories with known names only "invisibly".
  • writable: This also refers to readability. Some versions of Samba use one switch and the other switch, so it is advisable to use both to maintain compatibility and of course to avoid conflicting settings.
  • valid users: Valid users who can access the share. Of course, the permissions on your Linux system still apply. So they also have to be set up for this. For example, if it is a shared share, it can be shared by multiple users, etc.
  • map archive: By default, if files in the Samba share are modified from a Windows system, the executable bits of the files will be lost from the files because the file attributes are handled differently by Windows systems. This setting can eliminate this effect. So if you are sharing a shell that contains shell scripts, for example, and you do not want to lose the run rights, use this "no" option. In other cases it is irrelevant. (inserted: 2019-03-12)

Save and then restart the Samba daemon:

systemctl restart smbd.service

Create a Samba user

You also need to create a Samba user to access this share. These users are stored in a separate database managed by Samba.

For this operation is smbpasswd command serves. So, create a Samba user (and a Linux user) and password:

smbpasswd -a <felhasználónév>
Here, it is important to know that this command can only be used to create Samba users who already exist on Linux. So, if you want to create a new Samba user, you first need to create a regular user in the system using the useradd command. Otherwise, the smbpasswd command is "Failed to add entry for user <username>." gives an error message.

Accordingly, I created a Samba user for my user:

smbpasswd -a botond

Here, too, I entered the same password as I used to log in, so I could avoid any confusion. Of course, you can enter a different password for Samba shares.

List Samba users

If you have forgotten Samba users, you can list them using the following command:

pdbedit -L -v

The pdbedit command manages the Samba user database so you can do a lot with your records.

We are now fully ready to access the network.

Testing Samba sharing

If we were in a situation where there is no other computer available to try out our shared library, then we can test Samba sharing from the same system. For this we use the terminal (with any user) smbclient command:

smbclient -U <Samba felhasználó> //<hoszt>/<Megosztás>

You will be prompted for the Samba user password and then enter the SMB prompt where we can proceed to share, etc. So if we have done everything so far, then we can see something like this in the terminal:

Test Samba sharing from the command line

So we can be absolutely sure that our sharing is working.

The description on the next page and we'll be joining this sharing from Windows.


This description consists of several pages: