Linux to Windows File Sharing With Samba

One of the most common needs in a home or corporate network is to share files between computers. Linux provides this capability in a number of tools. To share files between Unix style operating systems, NFS is the standard tool. Samba, however, is a better tool in a network with Linux, Windows, and Macintosh computers.


Linux Root: What Root Is and How to Get it

A guide in choosing best Linux operating system

Samba is a free and open source implementation of Windows’s built-in file sharing service. It allows you to share your storage on a Linux computer with any other devices on the network which can access Windows shares. There are graphical tools to set up Samba, but these are not compatible with every desktop environment, so it is preferable to use the command-line tools. Also, this guide has been tested with Ubuntu 12.04, but it will work on any recent Debian or Ubuntu-based Linux distribution.

The first step to setting up Samba is to install it. Open a terminal and give the command to install Samba:

RELATED: Samba Download


sudo apt-get install samba

This will prompt you for your password and approval of the installation. After this completes, Samba is installed, but it is not yet configured.

To configure Samba, you will need to open the file /etc/samba/smb.conf as root. This is done in a text editor of your choice. An example command would be:


gksudo gedit /etc/samba/smb.conf

This command uses gksudo instead of sudo because gedit is a graphical program, and gksudo properly handles giving root permissions to graphical programs. Once you have opened smb.conf, there are a few changes you must make to your configuration. First, ensure there is a line that reads as follows:


security = user

This sets Samba’s security mode so that users need an account on the Linux computer to access its shares. This line is already included in Ubuntu 12.04.

Next you must configure a share. The smb.conf file has many predefined settings and administrator shares which can be left as is. Your share can be appended to the end of the file. A share is added to the end of the file and will look like the following:


[backup] comment = External USB Backup path = /media/backup browsable = yes guest ok = no read only = no create mask = 0750 valid users = bob invalid users = alice

In this example, the first line contains the share name in brackets. This is how the share will be named in computers connecting to it. The second line is an optional comment describing the share. The third line sets the path to the share. This must be a directory on your Linux system. The next lines are self-explanatory except for “create mask.” This command adds a restriction using Linux permissions on the access to content in the share. This restriction is in addition to any existing restrictions when the directory is not shared. For example, if /media/backup is not readable by bob when he is logged into the Linux computer, then he still will not be able to use it over Samba. However, if bob is part of the group ‘users,’ and /media/backup is readable and writable by the group users, then bob will only be able to read /media/backup when he accesses it via Samba.

If this sounds confusing, you likely don’t need to worry about it. Leaving the command as is will provide adequate security in a home network. Also, the “valid users” and “invalid users” lines may be omitted. This will allow anyone who can access the directory on the Linux machine to view it over Samba.

Append your share or shares to the end of smb.conf, and save the file. To make the changes take effect, either reboot the Linux computer, or issue the following commands to restart Samba:


sudo service nmbd restart


sudo service smbd restart

Once you have done this, you can browse your network from a Windows machine (or any device which can view Windows shares) and see your newly created shares. Your username and password for logging into the shares will be the same as your username and password on the Linux machine.

Samba is a versatile tool for much more than creating shares. Once you are more familiar with it, you can explore its documentation to take advantage of its other features.

Leave a Reply

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