Making A Linux File Server That Interacts With OS X Mavericks.

This is a non-development tutorial, but with Mavericks being really new there are no tutorials to make your file server interact with the OS smoothly. Because of this, I’m writing this small tutorial to setup your server to share files with OS X Mavericks. This may or may not work with OS X Lion and OS X Mountain Lion, but you lose nothing trying, right?

Last weekend I decided to ditch my Windows Desktop altogether and to make my beautiful 27” Inch iMac my main computer. The reason I stuck with Windows for so long is that I just cannot stash thousands of Gigabytes in my iMac. In other words, storage was the only reason I was using Windows. But then I thought, wouldn’t it be great to kill my Windows setup altogether, and convert all this hardware into a file server? I said yes, and that’s exactly what I did.

I’m incredibly illiterate when it comes to Linux and file servers. This was my first time setting a file server, actually. I was going to use FreeNAS. I looked at many OS alternatives for this, but I decided to stick with Ubuntu. If you’re in a similar situation, follow along this tutorial and hopefully by the end of it you will have a working Ubuntu file server that can communicate painlessly with your Mac.

1. Things to Consider: Your File Server Won’t use AFP.

If you don’t have much of a technical background and just want to have your file server up and running, feel free to skip this paragraph.

It will use SMB (yes, Windows’ – ironic in my case, isn’t it?). Why? Apple has the nasty habit of killing many of their technologies in the background with no formal announcement, but this was spotted in some technical documents. Basically, Apple will shift from AFP file sharing to SMB2 in OS X 10.9 Mavericks. It may come as a surprise to some but many people have had problems with AFP in Mountain Lion and below. Apple is dropping support for their own protocol in favor of Windows’ because it is more secure (or so they say).

There were many problems I had when I was first setting my file server up. I actually had no idea what this AFP protocol was, much less that it was being deprecated. When I first set the file server up, I used this tutorial to make Ubuntu announce and interact with OS X via AFP. I had no problems following that tutorial, but at the time of testing the problems were obvious. I was able to connect to my file server exactly once – then I restarted the server, and OS X Mavericks refused to connect anymore, burping this error message instead:

“The version of the server you’re trying to connect to is not supported. Please contact your system administrator to solve this problem.”

Googling tirelessly for hours I never found a solution to get that setup to work. I learned AFP was being dropped, and no one ever suggested a working around (there were a few workarounds, but none of them worked for me). So I just started over with a new Ubuntu Installation, and luckily, I succeeded putting my file server up.

Requirements for the File Server

I will not talk about the hardware requirements here. Personally I transformed an old computer into a file server. I assume you already have some old hardware lying around that you can use. But in case you’re curious, this is my server’s setup:

  • 5 internal 1TB hard drives.
  • 12 GBs RAM
  • VGA 1680 x 1020 Monitor

You can probably tell I won’t guide you through installing SSH to remotely control the server, as personally I control the server physically since it is next to my main computer anyway.

As for the software requirements:

  • Ubuntu Server. It probably works with the “normal” Ubuntu Desktop, but this is what I use. At the time of this writing, the latest version is Ubuntu Server 13.10, and you can get it here.
  • Samba. We need this so our server can be talked to with SMB. I will guide you through this.
  • Avahi (Optional). This isn’t needed but it does something really cool – announce the server via Bonjour. If you want to install this, I will guide you through.

1.1 So no Netatalk, then?

If you’re one of the poor souls who couldn’t get the Ubuntu File Server work properly with OS X Mavericks or (Mountain) Lion, you’re probably asking yourself why we aren’t using Netatalk.

Like I said at the beginning of this tutorial, we will be using SMB instead of AFP. Netatalk provided the required tools to talk to your server via AFP. Since Apple will most likely get rid of AFP completely at some time, we don’t need to use it at all.

2. Preparing the File Server

Installing and Configuring Ubuntu Server

How to install the server from scratch is out of this tutorial. I will focus mostly in Samba to make sure your Ubuntu can actually talk to your OS X. So go ahead and install it, as barebones as you can/want. I didn’t do any different than clicking “next” until the installation started.

Just make sure you use a different computer and account name. There seems to be some sort of conflict when OS X has the same account name as the file server.

Additionally, you will need to give Ubuntu an static IP address or use a .local name. Personally I gave the Ubuntu machine an static IP. Much easier to work with with my home network.

Installing and Configuring Samba: A Very Important Piece of the File Server

This is the most monotonous and longest part, but it isn’t so bad. Make sure you’re ready to spend 15 minutes of your time. To get this right I actually had to follow two different tutorials, and I have compiled them into one for you:

Step 1: Open Up The Terminal

I hate silly steps like this but let’s put them in for the sake of completeness. Open up a terminal window. We’re going to do everything as root to save ourselves the constant “sudo”. Type in:

sudo su

We’re going to be editing a few files later on. I like to use Linux’s included gedit to edit said files. Others may prefer, to use Nano, Vi, Vim, etc.. In case you’re like me and prefer a nice GUI, please install gksudo. This is irrelevant to the tutorial, but you shouldn’t execute GUI programs via the command line with sudo, even when you do need superuser permissions. Instead, to execute GUI programs via the command line with sudo permissions, execute them with gksu (or gksudo) instead. To install gksudo:

apt-get install gksu

To use it when you aren’t using the command line as root:

gksu gedit somefile

Or:

gksudo gedit somefile

When you want to share new directories via Samba later on, you will need to edit a file, and if you like gedit, you better use this to launch it instead of sudo from now on. So maybe it is a very little relevant after all!

Step 2: Install and Configure Samba for the File Server

With your shiny super user permissions, it’s time to install Samba:

apt-get install libcups2 samba samba-common

Once it’s done installing, we have to do a couple of configurations. We need to edit

/etc/samba/smb.conf

now:

gedit /etc/samba/smb.conf

This will launch gedit with Samba’s configuration file. Press Ctrl + F and type in “security =” so you’re taken to this area:

[...]
# "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
[...]

Remove the comment (the pound sign) from the last line, and add

username map = /etc/samba/smbusers

below it, so you have:

[...]
# "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
  username map = /etc/samba/smbusers
[...]

Save (Ctrl + S) the file and quit gedit so you have control over the terminal window with su.

Restart Samba when done:

service smbd restart

Step 3: Creating Samba Users

Samba users are needed to interact with the file server.

The steps to create Samba users are simple as 1,2, which I will guide you through:

  1. Create a password for the user you want to create.
  2. Add that user to to the Samba users file.

To create the password for the Samba user:

smbpasswd -a <username>

Where username is the name of the new Samba account you want to create. For example:

smbpasswd -a Andy

Then open the

/etc/samba/smbusers

file:

gedit /etc/samba/smbusers

And add the username like this:

<username> = “<username>”

To the left you put the name of the Ubuntu account that will have to this Samba account, and to the right, the name of the Samba account it has access to.

So if my Ubuntu account is called “andyfileserver” and the Samba account is called Andy, it would be like this:

andyfileserver = "Andy"

Save the file and restart Samba once again.

service smbd restart

And that’s it! You can now connect to your file server with your OS X Mavericks by going to Finder > Go > Connect to Server…

Sharing Folders

This is really out of the scope of the tutorial. There are many configurations for shared folders, but to get you started, you add some entries to your

/etc/samba/smb.conf

file. Open it and add your entries at the end of the file, like this:

[theroot]

comment = File Server
path = /media/andy
read only = no
writable = yes

[bluray]

comment = Optical Drive
path = /cdrom
read only = yes
writable = no

You essentially mount directories. What is in the first [] brackets is what your Mac will see as their name in the file server. I have “theroot” and “bluray”, so for me this looks like this:

Screen Shot 2013-10-28 at 6.49.00 PM

Again, there are many configurations so you may want to look how to configure Samba share folders for your needs. you can even assign different permissions and everything.

3. (Optional) File Server Announcing to the Network

You have finished the most important part and basically you can use your file server now, but this little extra step is cool in my opinion. Instead of having to do Finder > Go > Connect to Server… Every time we want to connect to the server, why don’t we show up in Finder’s left bar?

Screen Shot 2013-10-28 at 6.35.52 PM

To do that we need to install Avahi. Avahi is a simple file server daemon that announces to the network when it has connected, basically Bonjour. With this instead of telling OS X Mavericks to find the server, we can tell the server to tell everyone when it’s connected. In that way our server will appear as extractable media in the left bar of any finder Window, and it’s much easier and pleasant to interact with it using this method.

Luckily, installing and configuring Avahi is really fast and simple.

If you still have your su terminal window, type this in:

apt-get install avahi-daemon avahi-utils

Then open and edit the file

/etc/avahi/services/smb.service

(the file will be blank and that’s fine – you’re creating it from scratch):

gedit /etc/avahi/services/smb.service

And copy and paste this into it:

<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
 <name replace-wildcards="yes">%h</name>
 <service>
   <type>_smb._tcp</type>
   <port>445</port>
 </service>
 <service>
   <type>_device-info._tcp</type>
   <port>0</port>
   <txt-record>model=RackMac</txt-record>
 </service>
</service-group>

And that’s it! You don’t even need to restart Avahi. It will automatically announce to the network and your Mac will see your file server in Finder to the left.

And that’s it! I hope you find this tutorial useful, as personally I had a hard time configuring my file server to talk properly with OS X Mavericks.

Linklist:

These are the original tutorials I used:

http://www.howtoforge.com/ubuntu-13.04-samba-standalone-server-with-tdbsam-backend
http://www.howtogeek.com/howto/ubuntu/install-samba-server-on-ubuntu/
http://www.macdweller.org/2012/05/13/samba-bonjour-with-avahi/

Positive SSL