Installing latest Samba on Ubuntu 12.04

I am in the process of rebuilding my home server which will run Ubuntu Server – I will be putting up a series of detailed posts on my philosophy and experiences through this process. In the meantime, here’s the scoop on setting up the latest version of Samba on Ubuntu 12.04. This post provides a little bit of background to understand why Ubuntu 12.04 doesn’t have the latest version of Samba available, why you should not put the default version of samba available via apt-get install samba and what you need to do to get the latest stable version of Samba installed on your Ubuntu 12.04 server.

Ubuntu 12.04 is the current long term support release of Ubuntu. For server systems, this is the best choice as you really want a stable distribution that will be supported for an extended period of time with updates and LTS releases of Ubuntu is exactly that. One drawback however is that LTS releases do not have the latest and greatest versions of packages available – this makes sense as you don’t want untested/unproven things in your LTS release. And once the LTS release has been around for a while, it is just harder to justify creating the latest version of foo for LTS unless there’s a compelling reason like security – LTS releases are mostly in maintenance mode and while that brings you stability, it also brings you staleness.

Please bear with me for a bit of back-story on why I tried to get the latest stable version of Samba on Ubuntu 12.04 LTS – it is a bit long-winded but important as I suspect more people will be bitten by this issue.

Backstory

tl;dr summary: The default out of the box setup of Samba 3.6.3 in Ubuntu doesn’t play well with the default out of the box setup of SMB on Windows 8.1 – You will not even be able to list shares in the Ubuntu box from Windows.

Samba is software that allows a Linux machine to share resources from and with Windows machines. I will ignore the enterprise aspect of Samba for this post as my setting is my home where I don’t need these features but you can read all about Samba here.

I installed Samba through

sudo apt-get install samba

on my Ubuntu server box and created a share by editing smb.conf. I added and enabled a Samba capable user through smbpasswd. Then I verified that I was able to access the share locally using smbclient. Everything seemed to be working fine. Now for the critical test – trying to access the share from my Windows 8.1 machine. I tried using explorer first, because hey, that’s probably what I will be doing most of the time right? I did see the machine listed in network neighborhood – that’s good, indicates all’s well with DNS and NMBD. I clicked on it and it popped up an error – network path not found! Oops – ok, time to switch to command line. I tried

net use \\ubuntubox\resource -u [email protected]

– no dice, it was still saying network path not found. Ok, let’s try with IP address – tried

net use \\ubuntuip\resource -u [email protected]

This time it seemed to do a little better but the end result was still failure – this time it failed with access denied. At this point, I was stumped – clearly there’s no DNS issue here, yet access by IP is working slightly better than access by name.

Definitely seemed like a Samba interop issue with Windows 8.1 for the version of Samba I was running.

smbd --version

on the Ubuntu box showed that 12.04 is stuck with Samba version 3.6.3. The current one is 4.1.4 and 4.x is a major rewrite of Samba. But still, if it is only a matter of simple configuration changes, why not try that first – so I fired up wireshark on my windows machine to capture the network trace for the failed net use command by name to see what was going on. What I saw was that the Windows 8.1 machine was sending a negotiate protocol request and was getting back a TCP reset from the server. Clearly, the Samba server didn’t like the very first request from my Windows 8.1 box. While I could try to go on to figure out what the issue was and how to workaround it, I decided that a better option would be to update to the latest Samba release instead.

Installing latest Samba on Ubuntu 12.04

Here are the steps you follow to install the latest Samba version on Ubuntu 12.04:

First, uninstall the existing Samba install in your machine:

sudo apt-get remove samba

Next, uninstall any packages that are no longer required because Samba has been removed. This is important because the default Ubuntu install of samba brings in everything and the kitchen sink with it (things like CUPS integration, Avahi support etc. which most people shouldn’t care about). You can do this by running:

sudo apt-get autoremove

Next, download the sources for the latest stable release of Samba and unpack it – you can get them from here.

wget http://www.samba.org/samba/ftp/stable/samba-4.1.4.tar.gz
tar xvfz samba-4.1.4.tar.gz

Now, it is time to configure and build Samba. In order to build Samba, you will need build tools (configure, make, gcc etc.) and python development headers. In most systems the former should already be installed. If it is not, you can install by running

sudo apt-get install build-essential

. For the latter, you can install it by running

sudo apt-get install python-dev

Running configure should tell you if anything else is missing. So let’s go ahead and configure Samba – in my case, I don’t need CUPS or iprint support, didn’t need Active Directory support, didn’t need avahi or glusterfs. In addition, I wanted to keep the Samba configuration files in /etc/samba instead of the default /usr/local/samba/etc.

cd samba-4.1.4;
./configure --disable-cups --disable-iprint --disable-avahi --disable-glusterfs --without-ad-dc --sysconfdir=/etc/samba

You can run

./configure --help

to see all the options available. Once configure successfully completes, it’s time to build. Simply type make to build Samba.

make

If all goes well, now all the Samba binaries are built from the sources. At this point, you could simply run

make install

to install Samba. However, the downside to that is the install is completely outside the package management system and won’t show up in your usual tools/management workflows. Removal of the package/updates will need to be done manually and can quickly get tedious and out of control. This is where checkinstall enters the picture – checkinstall essentially wraps around the make install procedure to produce an installable package (rpm, deb or slackware as you wish) and then installs using the package. This allows you to manage the package like you would any other package installed in the system. Install checkinstall by running

apt-get install checkinstall

Now, run

sudo checkinstall

You should see a menu – it is important that you change defaults here. Not changing the name of the package or the provides will cause pain as the default name and provides is samba which makes the package manager lookup older dependencies. In short, Hit 2 and change name from samba to

samba-4.1.4

then hit 11 and change provides from samba to

samba-4.1.4

This will then take you through a sequence of steps at the end of which you should hopefully have a functioning install of Samba 4.1.4 on your machine. One thing that wasn’t installed through this process were the man pages. I wrote this simple bash script to install the man pages – run the script from the docs/manpages folder inside the Samba source directory (after manually creating the /usr/local/samba/share/man folder):

#!/bin/bash
base_man_path="/usr/local/samba/share/man"

for f in *
do
    filename=$(basename "$f")
    extension="${filename##*.}";
    manfiledest="$base_man_path/man$extension"
    [ -d "$manfiledest" ] || mkdir $manfiledest
    cp $f $manfiledest
done

The default location for the install is /usr/local/samba and all the Samba package related files should be here under different folders. Edit /etc/sudoers and /etc/environment to add /usr/local/samba/bin and /usr/local/samba/sbin to the path. Edit /etc/manpath.config to add /usr/local/samba/share/man to the man path.

The final missing piece in the install is a startup script for Samba. You can just go here and pick the last script on there and use that with suitable tailoring for your environment.

I updated my /etc/samba/smb.conf file to create the share and added and enabled the share user through smbpasswd and voila, everything just worked. I am able to access Windows 8.1 shares from my Ubuntu box and the Ubuntu shares from my Windows 8.1 box.

Edit 2/16/2014: There’s a crashing bug in Samba 4.1.4 when accessing the shares from Windows 8.1 – please see this post for more details on the fix.

Edit 3/1/2014: Samba 4.1.5 is now available with the fix for the crashing bug among others. Also, changed the title.

1 Reply to “Installing latest Samba on Ubuntu 12.04”

  1. Installing samba-4.3.4 on Linux Mint 17.3

    Excellent piece by Ram! Kindly provide some step by step on the following:

    Edit etc sudoers and etc environment to add usr local samba bin and usr local samba sbin to the path.
    Edit etc manpath.config to add usr local samba share man to the man path.

Leave a Reply

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