How-To Geek

Tophosts UK for the Top 10 Dedicated Web Hosts.
Deposit $250 and get free Forex VPS server. EAs and Scalping allowed
Installs on USB Key, plug it into any PC and run your X sessions.

Install Samba Server on Ubuntu

If you want to share files between your Ubuntu and Windows computers, your best option is to use Samba file sharing.

To install, first open a terminal window and enter the following command:

sudo apt-get install samba smbfs

We’ve got samba installed, but now we’ll need to configure it to make it accessible. Run the following command to open the configuration file, substituting your editor of choice:

sudo gedit /etc/samba/smb.conf

Find this section in the file:

####### Authentication #######

# “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/Samba-HOWTO-Collection/ServerType.html
# in the samba-doc package for details.
;  security = user

Uncomment the security line, and add another line to make it look like this:

security = user
username map = /etc/samba/smbusers

This will set Samba to use the smbusers file for looking up the user list.

Create a Samba User

There are two steps to creating a user. First we’ll run the smbpasswd utility to create a samba password for the user.

sudo smbpasswd -a <username>

Next, we’ll add that username to the smbusers file.

sudo gedit /etc/samba/smbusers

Add in the following line, substituting the username with the one you want to give access to. The format is <ubuntuusername> = “<samba username>”.  You can use a different samba user name to map to an ubuntu account, but that’s not really necessary right now.

<username> = “<username>”

Now you can create samba shares and give access to the users that you listed here.

Share User Home Directories

Don't show again X

Daily Email Updates

You can get our how-to articles in your inbox each day for free. Just enter your email below:


Email:
Sign up for Dropbox today. It's completely free, you guys!

Comments (40)

  1. Ross

    Worked for me setting up a debian server on my slug. Thanks!

  2. Brian

    Great HOWTO. this worked perfectly. I was debating on using OpenFile but when I saw how easy this was, I chose this. Since Ubuntu is so stable and never needs to be restarted, I really think this was the right choice.

  3. The Geek

    I’m glad it worked for you guys! It took me quite a while to figure it out myself =)

  4. hhcv

    Hi,

    I had some problems with this guide. To fix, add the user before creating the password!

    Cheers.

  5. manolis

    The how-to is indeed very helpfull. I have still though a
    little problem. I can see either machine on the network but
    is seems that I am not permitted to access them. I am running
    Ubuntu Edgy (6.10) under VMWare on WinXP. Any ideas ?

  6. Lee

    Thanks, man! I had SAMBA installed and, for some reason, it just quit working. I uninstalled it and used your instructions and IT WORKS!

    Keep up the excellent work!

  7. Themba

    I just tried Samba Server on the network, It works great.

  8. Lee

    Why do I have to keep turning off the firewall on my Linux computer? Is there a way so it will work without doing that each time?

  9. hadge

    Hi, one problem for me – complete newbie – when I type the command – sudo smbpasswd -a – I get this error message – bash: syntax error near unexpected token `newline’ – what’s that about then?
    ;0)

  10. jimsg

    To reemphasize what hhcv said: I also needed to do
    sudo adduser SomeNewUserName

    (and give this new user a password)

    before I could successfully run

    sudo smbpasswd -a SomeNewUserName

    The first creates a UNIX user, the second creates an SMB user. I don’t know if the two passwords need to be the same, but I made them the same just in case.

  11. Satish

    Hi man thx a lot now I slove the samba problem…..

    hey if you have the some trick for linux can you send me actualy I have exam for

    RHCE in spetember so I need hard study thx

  12. smj

    thanks a million, never been able to get it to work till now, really nice help for a newbie like me

  13. nogg3r5
  14. ogomoe

    Installing Samba on Opensuse 11.0 is different and I had to use nano as a text editor instead of gedit, but everything after the installation step in this how-to is spot-on.

    Anyway, the point I’m trying to make is that this Ubuntu how-to is the most simple answer I found to get Samba working with Opensuse 11.0, imagine that! ;)

    Thank you, Geek!

  15. ghofur

    “cannot locate remote server” after install samba what goes wrong??? any idea?

  16. Ambika

    Can any body inform me what is wrong with samba setup. It is showing below logs during installation.
    root@BHUWS042:~# sudo apt-get install samba smbfs
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Package samba is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source
    However the following packages replace it:
    smbclient samba-common
    E: Package samba has no installation candidate
    root@BHUWS042:~# sudo apt-get install sambaclient smbfs
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Couldn’t find package sambaclient
    root@BHUWS042:~# sudo apt-get install samba-common smbfs
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    samba-common is already the newest version.
    Package smbfs is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source
    E: Package smbfs has no installation candidate
    root@BHUWS042:~#

  17. shane

    I’m new also, can I get more detailed commands like how to save the the part where we change the “security = user
    username map = /etc/samba/smbusers”
    I can get the recording to come up, but just not sure what keys to press.
    Thanks!!

  18. george

    Hi Ambika,

    You need to enable the repository for this error. follow the instructions from this web link
    “http://www.howtogeek.com/howto/ubuntu/adding-extra-repositories-on-ubuntu/” . After editing the /etc/apt/sources.list file don’t forget to issue the below command

    sudo apt-get update

    and then try to install the samba software by issuing sudo apt-get install samba smbfs, you will be done.

    rgds
    george

  19. Roque

    Ok, Im new on this, I barely have a guess on what uncomment means,,,

    I tried this:
    sudo gedit /etc/samba/smb.conf

    Made this:
    ####### Authentication #######

    “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

    I saved and closed.

    Then tried this on the terminal:
    sudo smbpasswd -a

    and I got this:
    bash: syntax error near unexpected token `newline’

    Can’t continue, please help for newbies.

  20. Logics

    @Roque
    a comment is any line that begins with a “#” or a “;”

    To ‘uncomment’ a line means to remove the preceding “#” or “;” from the start. In your case, the line
    ;security = user
    should become
    security = user
    with the “;” at the start removed.

  21. Eric

    I tried these steps in Ubuntu 9.04 Desktop Edition (32bit). I can succesfuly map a share folder from Windows Desktop via samba user account. But do not have write access to the folder. Don’t know why? I don’t want other people or guest account to access this folder. Can Geek halp on this?

  22. jack

    HOW DO I GO ABOUT TRANSFERING FILES FROM ONE NODE TO ANOTHER USING SAMBA

  1. arben

    to hadje: you need to remove the around username…they are not meant to be typed in.

  2. ajay

    hey brother
    i just want to say that how can configure sambha in ms-dos desktop pc
    any body help me

  3. matthewstech

    I’m new to Linux and this tutorial was excellent! Spent hours on the web trying to get this up and running and this was the ticket.

  4. ubuntushell.com

    this blog is ok, thanks for share contents .

  5. Harry

    I would like to move my samba of my existing drive and install it on a separate drive.
    I will have to install the new drive, mount it change the path for samba and then copy all my existing files to new location.
    Please help.
    Thanks
    Harry

  6. Samuel

    Hi Guys,
    Thanks For the Advice. But I have one question.
    Dose this sharing work with win server 2008. I’ve an error message saying “Unable to mount ; Failed to retrieve shared list from server “.
    What shall I do?

    Thanks in Advance.

  7. imanoobe

    hi i’m a newbe to linux.
    i’ve edited the smb.conf
    like so
    security = user
    username map = /etc/samba/smbusers
    but when i enter command to create user
    sudo smbpasswd -a
    i get this error bash: syntax error near unexpected token `newline’
    now when i check the path for the file smbusers under /etc/samba/smbusers that file is not there.
    need help to create smbusers file so that the create user command will be able to write to that file. please help i’m really new to this

  8. Crystal

    Thanks, was trying to learn about samba and how to make it work and this made it all simple. Thank you so much.

  9. Russ

    I’ve never had a Linux tute work first time – this did.

    Awesome, thanks for sharing – worked for Ubuntu Server 10.10

  10. huylv

    Hi i was unable to add a user after executed this sudo smbpasswd -a
    the error is “Failed to add entry for user ”
    any idea?

  11. Indie

    @huylv: Read the other comments, with security = user the user needs to have a local UNIX account.

  12. Indie

    man 8 smbpasswd:

    -a

    Note that the default passdb backends require the user to already exist in the system password file (usually /etc/passwd), else the request to add the user will fail.

  13. myrocode

    thank you, it was so easy!

  14. Ceci

    Create the user first!!! :)

  15. JB

    finally!

    After searching multiple days why samba didn’t work, this actually made it work!
    For now its a great way, since I can give ppl finally access to the shares!
    later on, I guess i gonna change it so i can use a mysql database to do the checkups :)

    thankyou!,
    JB

  16. rabrant

    Your tutorial is very good. It worked right away for sharing Linux with Windows. However, I wanted to be able to access my Windows files from Linux. I kept on running into this error: Connection to failed (Error NT_STATUS_UNSUCCESSFUL)

    I finally resolved this. All that needs to be done is to add that computer to your /etc/hosts file. i.e.: My computer name is PC-VISTA and my IP is 192.168.1.100. Just add the following to /etc/hosts:

    PC-VISTA 192.168.1.100

    Bada-bing! Problem solved!

  17. charmingkid

    thx very much!!

  18. Pawan

    Haylo all!
    I’m extremely new to these stuff.
    I’m using Windows XP SP2 and I have Ubuntu 10.10 on my VirtualBox 4.1.2.
    And I need to install Samba on Ubuntu and access it from Windows.
    I have installed Samba and Configured smb.conf.
    My ubuntu computer name is dbs-pc and my windows computer name is PAWAN-IBM-T61p.
    Now what to do in windows to access ubuntu’s home directory from Windows?
    Please help.

Comments are closed on this post.

If you'd like to continue the discussion on this topic, you can do so at our forum.


Go to the Forum