Revision 5 as of 2005-07-23 05:28:02

Clear message

   Work in progress
  (feel free to add notes)

What is Samba and when do I need it?

attachment:IconsPage/IconSambaShares.png To make a long story short : samba is a set of tools to share files and printers with computers running Windows. It implements the SMB network protocol, which is the heart of Windows networking.

You need samba to :

  • act as a client with Windows servers : access file shares and remote printers,
  • act as a server for Windows (or samba) clients : share folders and printers, including PDF pseudo-printers so all the computers in your network may write PDF files,
  • act as a domain controller in a windows network (authenticating users, etc.)
  • do some more complex stuff, such as using a windows domain controller to authenticate the users of a linux/un*x machine...

The samba project was started in 1992 by Andrew TRIDGELL. It's now an important piece of software in the linux world when it come to make windows and linux machines interoperate.

More information about Samba can be found at Also check out the links at the bottom of this page.

Do you need Samba? Maybe not:

  • If you want your Windows computer to be able to use (via a network) a printer that is attached to a Linux computer, you don't need Samba. CUPS can be configured to make the printer accessible to the network. (See the question in the FAQ.)
  • You don't need Samba to share directories between two Linux computers. You can use NFS.

Installing Samba

Installing samba is really simple, just type

    sudo apt-get update 
    sudo apt-get install samba

or use synaptic (see SynapticHowto)

Configuring your computer

Start the network configurator using the following menu:

Computer -> System Configuration -> Networking

Or Ubuntu 5.04 "Hoary Hedgehog" Release:

System -> Administration -> Networking


You will need the General tab, in the middle.

Time to fill in your settings:

    Host Settings
      Hostname:       <yourcomputer>
      Domain name:    <yourdomain>

    Windows Networking
      Tick Enable windows networking
      Description:       <whateveryouwant>
      Domain/Workgroup:  <yourdomainorworkgroup>

   If you want tick WINS server  <thenameoripaddressofyourwinsserver>

Note: If you do not know, ask your network-administrator. Typical settings for the workgroup field are "mshome" or "workgroup".

The important settings here are your hostname, which should be filled in already, and the domain/workgroup. Press OK on both windows and the first part of cooperating with windows-machines is done.

Browsing samba shares

Ubuntu and Gnome make it easy to access files on a windows network share.

Open the Computer Menu, then click on "Network". You'll see a "windows network" icon, open it. The next window shows all the domains/workgroups found in your network. Inside each domain/workgroup you get all the computers in it (that is, those sharing something !). Double-click on a computer icon to access its shares and files. Could it be easier ?

Before showing a computer's shares, your system may prompt you for a name and password. Fill in the form with the credentials of a valid user for the computer you're connecting to. You may additionally store that password in your keyring for convenience.

Mounting a samba share

Mounting a share on the local filesystem allows you to work around programs that do not yet use GnomeVFS to browse remote shares transparently. To mount a samba share, first install smbfs:

    sudo apt-get update 
    sudo apt-get install smbfs

To allow non root accounts to mount shares, change the permissions on the smbmnt program thus:

    sudo chmod u+s /usr/bin/smbmnt

The following will mount the myshare folder on myserver to /home/yourusrname/mnt:

    smbmount //myserver/myshare /home/yourusrname/mnt

In order to have a share mounted automatically every time you reboot, you need to do the following:

Open a shell as root

    sudo -s

Create a file containing your Windows/Samba user account details:

    vi /etc/samba/user should contain two lines as follows:

    username = george
    password = secret

Change the permissions on the file for security:

    chmod 0600 /etc/samba/user

Now create a directory where you want to mount your share (e.g. /mnt/data):

    mkdir /mnt/data

Now edit the file system table (/etc/fstab) and add a line as follows:

    //server/share   /mnt/data   smbfs   credentials=/etc/samba/user,rw,uid=bob   0   0

...where 'bob' is the non-root user you log into ubuntu with, 'server' is the name or address of the windows machine and 'share' is the name of the share.

To mount the share now, just use the following command as root. It will mount automatically on subsequent reboots.

    mount /mnt/data

to be continued...

Configuring your computer as a server

The next part does not have a good graphical tool yet, unfortunately, so we must use the command line. It is not difficult, just be careful with typos.

First open a terminal: Applications > System Tools > Terminal and open the file smb.conf

    sudo nano -w /etc/samba/smb.conf

How to Save: To save in nano use "ctrl/o" than "ctrl/x".

Tip: Replacing nano with gedit gives you a nice graphical editor.

The file *smb.conf* is divided in several sections:

    Global Settings
    File sharing
    Share Definitions

Let's start with Global Settings. Here you will see several lines, which you can also see in the graphical networktool like workgroup and wins server. If you changed everything to your liking already then you can skip this section, if not change to what you need. If you do not know what items mean, leave them be and read the relevant part in the real samba-howto instead of randomly changing them. It will save you trouble-shooting later.

The important part for us is File sharing. We need to change:

       comment = Home Directories
       browseable = no

    # By default, the home directories are exported read-only. Change next
    # parameter to 'yes' if you want to be able to write to them.
       writable = no

    # File creation mask is set to 0700 for security reasons. If you want to
    # create files with group=rw permissions, set next parameter to 0775.
       create mask = 0700

    # Directory creation mask is set to 0700 for security reasons. If you want to
    # create dirs. with group=rw permissions, set next parameter to 0775.
       directory mask = 0700

This describes your /home folder. Usually you want to share this folder in a home-environment, because these are the files you want to share. To do so, make the following changes:

       comment = Home Directories
       browseable = yes

    # By default, the home directories are exported read-only. Change next
    # parameter to 'yes' if you want to be able to write to them.
       writable = yes

    # File creation mask is set to 0700 for security reasons. If you want to
    # create files with group=rw permissions, set next parameter to 0775.
       create mask = 0775

    # Directory creation mask is set to 0700 for security reasons. If you want to
    # create dirs. with group=rw permissions, set next parameter to 0775.
       directory mask = 0775

This finishes sharing your /home folder. The last thing we need to do is fixing a user.

Add users who can access your shares with the 'smbpasswd' command.

    bash:~$ sudo  smbpasswd -a username

    New SMB password:
    Retype new SMB password:
    Added user username.

Restart Samba for every change to users/passwords or 'smb.conf'

    bash:~$ sudo /etc/init.d/samba restart

That's the basis of Samba file-sharing. Please leave your comments about what else is needed here.

Complicating things a little

We started with the base of samba file-sharing. The above-mentioned items should be enough to get you started. Next we will add details that you might or might not need.

If you have more the one networkcard

If you have more the one networkcard (or interface) then you have to define where you want samba to run. In smb.conf under the [global] section, add:

    "interfaces =,"
    "bind interfaces only = yes"

The first address (, is a loopback network connection (it's your own machine). The second address (, is the address of the card you want samba to run on, the second number (24) is the subnet default for a CLASS-C network. It may vary depending on your network.

With "bind interfaces only" you limit which interfaces on a machine will serve SMB requests.

You can limit which IP address can connect to your Samba server adding these lines:

    "hosts allow =,,"
    "hosts deny ="

The loopback address must be present in the first line. The second line deny access from all IP address not in the first line.

From WouterdeVries Sat Dec 4 19:42:39 +0000 2004 From: Wouter de Vries Date: Sat, 04 Dec 2004 19:42:39 +0000 Subject: shares-admin Message-ID: <20041204194239+0000@>

You could say something about shares-admin, which lets you add shares to the samba server.

From MaartenJongepier Tue Dec 28 17:06:24 +0000 2004 From: Maarten Jongepier Date: Tue, 28 Dec 2004 17:06:24 +0000 Subject: smb:// protocol Message-ID: <20041228170624+0000@>

You doesn't always need samba, isn't is? You can also use smb://windows-compu/share. That works too I thought

Not much here about how to use a Windows printer from Linux. I figured out how to get my Ubuntu machine to access the USB printer (HP LaserJet 1012) on my Windows XP machine, so I'll post that here (at least I will be able to find this when I forget how I did it).

1. Installed the HP LaserJet 1012 on the XP box using the CD that came with the printer.

2. Shared the printer as "LJ1012" (or whatever you want to call it).

3. Created a user named "Guest" (with no password) and added that user under the Security tab for the printer.

4. On Ubuntu, from the command line, entered: sudo adduser cupsys shadow (this is absolutely KEY!!!)

5. Downloaded the best driver (HP-LaserJet_1012-pxl1010.ppd) from and copied to /usr/share/cups/model/foomatic-ppds/HP/

6. In Firefox, went to localhost:631 (for Cups)

7. Add Printer - when prompted, logged in as the primary user (my name, not root), with my usual password. This (plus step 4) gets around the problem of there not being a 'root' account in Ubuntu.

8. Chose Windows Printer (Samba) from Add Printer dialogs (way at the bottom of the list).

9. Used the network address smb://guest@WINMACHINE/LJ1012

10. Using the Gnome printer applet, adjusted the paper size to US Letter (applet sometimes freezes, but does not seem to do any harm).

What a friggin PITA, but it WORKED. This printer is a great buy.

From dturnbull Mon Mar 28 07:53:18 +0100 2005 From: dturnbull Date: Mon, 28 Mar 2005 07:53:18 +0100 Subject: Bleh, had to edit printers.conf Message-ID: <20050328075318+0100@>

I wanted to use the printer on a Windows system and had no luck with the GUI or the HTTP configuration interfaces. I ended up editing /etc/cups/printers.conf and changing (for example)

DeviceURI smb://WARRIOR/R300


DeviceURI smb://GUEST@WARRIOR/R300

After that everything else was configurable from the Gnome GUI. This was in Hoary preview.

From NickIrvine Thu Apr 7 14:03:47 +0100 2005 From: Nick Irvine Date: Thu, 07 Apr 2005 14:03:47 +0100 Subject: Addition to text Message-ID: <20050407140347+0100@>

When the text mentions using smbpasswd, it should be noted that the user added as username has to exist as a Linux user as well.

CategoryDocumentation CategoryCleanup