Using Ubuntu as a Windows File Server

Nathan Osman's Gravatar

Nathan Osman
published Dec. 8, 2013, 2:55 p.m.

Although there are a number of ways to provide networked storage for a set of machines running Ubuntu, these methods don't work very well as soon as you throw a Windows machine on the network. (Windows does provide support for NFS but you'll need Windows 8 Enterprise, so this isn't likely a practical option.) Luckily, Ubuntu provides an easy way to connect to Windows networks via the SMB protocol. The tool required for this is called Samba.


Installing Samba is easy:

sudo apt-get install samba


Things get a bit more interesting here. Ideally, there would not need to be any additional configuration after installation and everyone with a Unix account on the system could log in and access their home directory or some shared directory. But this isn't quite true.

Configuration settings (the ones that we need to adjust) are stored in /etc/samba/smb.conf. Take a minute to open the file and read the comments inside. The comments do an excellent job of describing the settings and what effect each of them has. We will be changing some of the settings so you will need to open the file as the root user.

The first few sections should be fine as-is unless you are joining a workgroup that isn't named "WORKGROUP" or have an unusual setup that requires additional configuration. The first section that we will need to edit is labeled "Authentication". You will need to uncomment the section = user setting by removing the "#" at the beginning of the line. It should look something like this:

# "security = user" is always a good idea. This will require a Unix account
# in this server for every user accessing the server. See
# /usr/share/doc/samba-doc/htmldocs/Samba3-HOWTO/ServerType.html
# in the samba-doc package for details.
   security = user

This will allow only users with Unix passwords on the system to connect to the computer.

The second section that needs to be edited is labeled "Share Definitions". Uncomment the three lines that begin with [homes] be removing the ";" at the beginning of each line. It should look something like this:

# Un-comment the following (and tweak the other settings below to suit)
# to enable the default home directory shares. This will share each
# user's home director as \\server\username
   comment = Home Directories
   browseable = no

This will allow each user to access their home directories. Now save the changes and close the file. Restart the Samba daemon with the following command:

sudo service smbd restart

Is That All?

At this point you might be tempted to try to log in from a Windows computer. You will quickly discover that this doesn't work - you will receive an authorization error.

SMB Error

Even if you enter the correct password, you will encounter this error. What gives? It turns out that Samba keeps track of passwords independently from /etc/passwd and /etc/shadow. So you will need to let Samba know what your password is. On the machine running Ubuntu, run the following command:

sudo smbpasswd -a <username>

Replace <username> in the command above with your Unix username. Now you should be able to connect to the share from within Windows explorer.

Windows Share

Creating a Shared Directory

At this point, each user can access their home directory. But what happens if you want a bunch of users to be able to access a single directory for collaboration? Well, that's easy enough.

# Shares the /var/sekret-projekt directory
   comment = Shared directory for collaboration
   writable = yes
   force create mode = 0766
   force directory mode = 0766
   path = /var/sekret-projekt

This will create a share at /var/sekret-projekt that is accessible to any logged in user. You can even assign a drive letter to the share.

Mounted Windows Share