Set up your new Ubuntu Server as a Samba Server

Jack Wallen
Sep 4, 2009
Updated • Nov 28, 2012

I recently did an illustrated guide to installing Ubuntu Server 9.04 ("Installing Ubuntu Server 9.04"). I did that for two reasons: 1) It was requested and 2) It will serve as a base for future articles that will cover many different topics. Having that foundation will be key to getting other services up and running.

In this article I am going to show you how to get a basic Samba Server up and running on top of that Ubuntu Server. Now, because the Ubuntu Server was set up as a headless server, the installation and configuration of Samba will be done completely from the command line. So get your fingers ready to type.

What is Samba?

Samba is a very handy tool that can do many things. The primary task it serves is to enable a Windows machine to access a Linux machine serving as a file and/or print server. Samba uses the SMB/CIFS protocols to enable communication between the Windows and the Linux machine.

Samba has often been thought of as very difficult to get up and running. It's not really that bad. Hopefully, by the end of this article, you will have a fairly good understanding of how to get it up and running.

Installing Samba

As I said, you will doing this completely from the command line. The command to issue is:

sudo apt-get install samba

You will have to enter your sudo password to continue with the installation. Depending upon your server installation, you might have to okay some dependencies. Go ahead and do this and then watch as Samba is installed.

Once installed you will have the Samba executable in /etc/init.d/. In order to start Samba you will issue the command:

/etc/init.d/samba start

Of course, before you start Samba, you will need to configure Samba. There are a few steps to take care of. Let's first deal with the configuration file.

Configuring Samba

Before you get too deep into this you might want to first read my article "Get To Know Linux: Understanding smb.conf". The Samba configuration file is located in the /etc/samba directory and is called smb.conf. When you first open up this file you may be overwhelmed. Let's avoid that by making a backup of the original smb.conf file. Change to the /etc/samba directory with the command:

cd /etc/samba

Now issue the following command:

sudo cp smb.con smb.conf.bak

Now you can open up the smb.conf file and erase the entirety of its contents. How do you do that? If you are using the Nano editor it's simple. With the file open hold the Ctrl key and the 'K' key down until the entire contents are gone. Or you can delete the file and create a new one. Your choice.

With a fresh smb.conf you are ready to re-create a file based on your needs. A good configuration to start with looks like:

netbios name = NETBIOS_NAME
workgroup = WORKGROUP_NAME
security = user
encrypt passwords = yes
smb passwd file = /etc/samba/smbpasswd
interfaces =

comment = COMMENT
writeable = yes
create mode = 0600
directory mode = 0700
locking = yes

Where everything in ALL CAPS (as well as the interfaces line) is unique to your needs.

The SHARE_NAME is what you want to share out to your users. So if you are setting up a file server for a number of users you will want to have a directory, say /data, that is shared out through Samba.

Once you have the smb.conf file configured to suit your needs you are ready for the last steps.

Adding users

This is the step that most people skip and wonder why Samba isn't working. For every user that needs to log in to the Samba server you have to add them with the help of the smbpasswd command. Let's say I need to add the user "pickles".  To add "pickles" I would issue the command:

sudo smbpasswd -L -a pickles

Now to make sure the users is enabled issue the command:

sudo smbpasswd -L -e pickels

Now restart Samba with the command:

sudo /etc/init.d/samba restart

Your Samba file server should be ready to go. Go to your windows machine and the Share should be visible. Double click on that share you and you will enter the username and password combination for any one of the users on the machine (as long as they were also added with smbpasswd). If you can not see it make sure your Windows machine is set up on the Workgroup.


Previous Post: «
Next Post: «


  1. DefStaar said on October 4, 2009 at 10:28 pm

    There’s an (important) ‘f’ missing in this line:

    sudo cp smb.con smb.conf.bak

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.